decompiled_code:
__int64 __fastcall si_opencl_device_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
char *v8; // r14
unsigned int v9; // er13

switch ( (int)a2 )
{
case 4096:
v8 = (char *)&si_gpu_device_type;
v9 = 4;
break;
case 4097:
v8 = (char *)&si_gpu_device_vendor_id;
v9 = 4;
break;
case 4098:
v8 = (char *)&si_gpu_num_compute_units;
v9 = 4;
break;
case 4099:
v8 = (char *)&si_gpu_work_item_dimensions;
v9 = 4;
break;
case 4100:
v8 = (char *)&si_gpu_work_group_size;
v9 = 4;
break;
case 4101:
v8 = (char *)&si_gpu_work_item_sizes;
v9 = 12;
break;
case 4102:
case 4103:
case 4104:
case 4105:
case 4106:
case 4107:
v8 = (char *)&si_gpu_num_stream_cores;
v9 = 4;
break;
case 4108:
v8 = (char *)&si_gpu_max_clock_frequency;
v9 = 4;
break;
case 4109:
v8 = (char *)&si_gpu_address_bits;
v9 = 4;
break;
case 4110:
v8 = (char *)&si_gpu_max_read_image_args;
v9 = 4;
break;
case 4111:
v8 = (char *)&si_gpu_max_write_image_args;
v9 = 4;
break;
case 4112:
v8 = (char *)&si_gpu_max_mem_alloc_size;
v9 = 8;
break;
case 4113:
v8 = (char *)&si_gpu_image2d_max_width;
v9 = 4;
break;
case 4114:
v8 = (char *)&si_gpu_image2d_max_height;
v9 = 4;
break;
case 4115:
v8 = (char *)&si_gpu_image3d_max_width;
v9 = 4;
break;
case 4116:
v8 = (char *)&si_gpu_image3d_max_height;
v9 = 4;
break;
case 4117:
v8 = (char *)&si_gpu_image3d_max_depth;
v9 = 4;
break;
case 4118:
v8 = (char *)&si_gpu_image_support;
v9 = 4;
break;
case 4119:
v8 = (char *)&si_gpu_max_parameter_size;
v9 = 4;
break;
case 4120:
v8 = (char *)&si_gpu_max_samplers;
v9 = 4;
break;
case 4121:
v8 = (char *)&si_gpu_mem_base_addr_align;
v9 = 4;
break;
case 4122:
v8 = (char *)&si_gpu_min_data_type_align_size;
v9 = 4;
break;
case 4123:
v8 = (char *)&si_gpu_single_fp_config;
v9 = 4;
break;
case 4124:
v8 = (char *)&si_gpu_global_mem_cache_type;
v9 = 4;
break;
case 4125:
v8 = (char *)&si_gpu_global_mem_cacheline_size;
v9 = 4;
break;
case 4126:
v8 = (char *)&si_gpu_global_mem_cache_size;
v9 = 8;
break;
case 4127:
v8 = (char *)&si_gpu_global_mem_size;
v9 = 8;
break;
case 4128:
v8 = (char *)&si_gpu_max_constant_buffer_size;
v9 = 8;
break;
case 4129:
v8 = (char *)&si_gpu_max_constant_args;
v9 = 4;
break;
case 4130:
v8 = (char *)&si_gpu_local_mem_type;
v9 = 4;
break;
case 4131:
v8 = (char *)&si_gpu_local_mem_size;
v9 = 8;
break;
case 4132:
v8 = (char *)&si_gpu_error_correction_support;
v9 = 4;
break;
case 4133:
v8 = (char *)&si_gpu_profiling_timer_resolution;
v9 = 4;
break;
case 4134:
v8 = (char *)&si_gpu_endian_little;
v9 = 4;
break;
case 4135:
v8 = (char *)&si_gpu_device_available;
v9 = 4;
break;
case 4136:
v8 = (char *)&si_gpu_compiler_available;
v9 = 4;
break;
case 4137:
v8 = (char *)&si_gpu_execution_capabilities;
v9 = 4;
break;
case 4138:
v8 = (char *)&si_gpu_queue_properties;
v9 = 4;
break;
case 4139:
v8 = si_gpu_device_name;
v9 = strlen(si_gpu_device_name) + 1;
break;
case 4140:
v8 = si_gpu_device_vendor;
v9 = strlen(si_gpu_device_vendor) + 1;
break;
case 4141:
v8 = si_gpu_driver_version;
v9 = strlen(si_gpu_driver_version) + 1;
break;
case 4142:
v8 = si_gpu_device_profile;
v9 = strlen(si_gpu_device_profile) + 1;
break;
case 4143:
v8 = si_gpu_device_version;
v9 = strlen(si_gpu_device_version) + 1;
break;
case 4144:
v8 = si_gpu_device_extensions;
v9 = strlen(si_gpu_device_extensions) + 1;
break;
case 4145:
v8 = (char *)&si_gpu_platform;
v9 = 4;
break;
case 4146:
v8 = (char *)&si_gpu_double_fp_config;
v9 = 4;
break;
case 4148:
v8 = (char *)&si_gpu_vector_width_half;
v9 = 4;
break;
case 4149:
v8 = (char *)&si_gpu_host_unified_memory;
v9 = 4;
break;
case 4150:
case 4151:
case 4152:
case 4153:
case 4154:
case 4155:
v8 = (char *)&si_gpu_num_stream_cores;
v9 = 4;
break;
case 4156:
v8 = (char *)&si_gpu_vector_width_half;
v9 = 4;
break;
case 4157:
v8 = si_gpu_opencl_version;
v9 = strlen(si_gpu_opencl_version) + 1;
break;
case 4158:
v8 = (char *)&si_gpu_linker_available;
v9 = 4;
break;
default:
fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s", a2, si_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0x157u, "si_opencl_device_get_info");
}
if ( a4 && a5 >= v9 )
mem_write(a3, a4, v9, v8);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
char *v8; // r14
unsigned int v9; // er13

switch ( (int)a2 )
{
case 4096:
v8 = (char *)&si_gpu_device_type;
v9 = 4;
break;
case 4097:
v8 = (char *)&si_gpu_device_vendor_id;
v9 = 4;
break;
case 4098:
v8 = (char *)&si_gpu_num_compute_units;
v9 = 4;
break;
case 4099:
v8 = (char *)&si_gpu_work_item_dimensions;
v9 = 4;
break;
case 4100:
v8 = (char *)&si_gpu_work_group_size;
v9 = 4;
break;
case 4101:
v8 = (char *)&si_gpu_work_item_sizes;
v9 = 12;
break;
case 4102:
case 4103:
case 4104:
case 4105:
case 4106:
case 4107:
v8 = (char *)&si_gpu_num_stream_cores;
v9 = 4;
break;
case 4108:
v8 = (char *)&si_gpu_max_clock_frequency;
v9 = 4;
break;
case 4109:
v8 = (char *)&si_gpu_address_bits;
v9 = 4;
break;
case 4110:
v8 = (char *)&si_gpu_max_read_image_args;
v9 = 4;
break;
case 4111:
v8 = (char *)&si_gpu_max_write_image_args;
v9 = 4;
break;
case 4112:
v8 = (char *)&si_gpu_max_mem_alloc_size;
v9 = 8;
break;
case 4113:
v8 = (char *)&si_gpu_image2d_max_width;
v9 = 4;
break;
case 4114:
v8 = (char *)&si_gpu_image2d_max_height;
v9 = 4;
break;
case 4115:
v8 = (char *)&si_gpu_image3d_max_width;
v9 = 4;
break;
case 4116:
v8 = (char *)&si_gpu_image3d_max_height;
v9 = 4;
break;
case 4117:
v8 = (char *)&si_gpu_image3d_max_depth;
v9 = 4;
break;
case 4118:
v8 = (char *)&si_gpu_image_support;
v9 = 4;
break;
case 4119:
v8 = (char *)&si_gpu_max_parameter_size;
v9 = 4;
break;
case 4120:
v8 = (char *)&si_gpu_max_samplers;
v9 = 4;
break;
case 4121:
v8 = (char *)&si_gpu_mem_base_addr_align;
v9 = 4;
break;
case 4122:
v8 = (char *)&si_gpu_min_data_type_align_size;
v9 = 4;
break;
case 4123:
v8 = (char *)&si_gpu_single_fp_config;
v9 = 4;
break;
case 4124:
v8 = (char *)&si_gpu_global_mem_cache_type;
v9 = 4;
break;
case 4125:
v8 = (char *)&si_gpu_global_mem_cacheline_size;
v9 = 4;
break;
case 4126:
v8 = (char *)&si_gpu_global_mem_cache_size;
v9 = 8;
break;
case 4127:
v8 = (char *)&si_gpu_global_mem_size;
v9 = 8;
break;
case 4128:
v8 = (char *)&si_gpu_max_constant_buffer_size;
v9 = 8;
break;
case 4129:
v8 = (char *)&si_gpu_max_constant_args;
v9 = 4;
break;
case 4130:
v8 = (char *)&si_gpu_local_mem_type;
v9 = 4;
break;
case 4131:
v8 = (char *)&si_gpu_local_mem_size;
v9 = 8;
break;
case 4132:
v8 = (char *)&si_gpu_error_correction_support;
v9 = 4;
break;
case 4133:
v8 = (char *)&si_gpu_profiling_timer_resolution;
v9 = 4;
break;
case 4134:
v8 = (char *)&si_gpu_endian_little;
v9 = 4;
break;
case 4135:
v8 = (char *)&si_gpu_device_available;
v9 = 4;
break;
case 4136:
v8 = (char *)&si_gpu_compiler_available;
v9 = 4;
break;
case 4137:
v8 = (char *)&si_gpu_execution_capabilities;
v9 = 4;
break;
case 4138:
v8 = (char *)&si_gpu_queue_properties;
v9 = 4;
break;
case 4139:
v8 = si_gpu_device_name;
v9 = strlen(si_gpu_device_name) + 1;
break;
case 4140:
v8 = si_gpu_device_vendor;
v9 = strlen(si_gpu_device_vendor) + 1;
break;
case 4141:
v8 = si_gpu_driver_version;
v9 = strlen(si_gpu_driver_version) + 1;
break;
case 4142:
v8 = si_gpu_device_profile;
v9 = strlen(si_gpu_device_profile) + 1;
break;
case 4143:
v8 = si_gpu_device_version;
v9 = strlen(si_gpu_device_version) + 1;
break;
case 4144:
v8 = si_gpu_device_extensions;
v9 = strlen(si_gpu_device_extensions) + 1;
break;
case 4145:
v8 = (char *)&si_gpu_platform;
v9 = 4;
break;
case 4146:
v8 = (char *)&si_gpu_double_fp_config;
v9 = 4;
break;
case 4148:
v8 = (char *)&si_gpu_vector_width_half;
v9 = 4;
break;
case 4149:
v8 = (char *)&si_gpu_host_unified_memory;
v9 = 4;
break;
case 4150:
case 4151:
case 4152:
case 4153:
case 4154:
case 4155:
v8 = (char *)&si_gpu_num_stream_cores;
v9 = 4;
break;
case 4156:
v8 = (char *)&si_gpu_vector_width_half;
v9 = 4;
break;
case 4157:
v8 = si_gpu_opencl_version;
v9 = strlen(si_gpu_opencl_version) + 1;
break;
case 4158:
v8 = (char *)&si_gpu_linker_available;
v9 = 4;
break;
default:
fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s", a2, si_err_opencl_note);
_assert_fail("info", "opencl-device.c", 0x157u, "si_opencl_device_get_info");
}
if ( a4 && a5 >= v9 )
mem_write(a3, a4, v9, v8);
return v9;
}

original_code:
uint32_t si_opencl_device_get_info(struct si_opencl_device_t *device, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 uint32_t size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1000:
  size_ret = 4;
  info = &si_gpu_device_type;
  break;
 case 0x1001:
  size_ret = 4;
  info = &si_gpu_device_vendor_id;
  break;
 case 0x1002:
  size_ret = 4;
  info = &si_gpu_num_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &si_gpu_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &si_gpu_work_group_size;
  break;
 case 0x1005:
  size_ret = 12;
  info = si_gpu_work_item_sizes;
  break;
 case 0x1006:
 case 0x1007:
 case 0x1008:
 case 0x1009:
 case 0x100a:
 case 0x100b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x100c:
  size_ret = 4;
  info = &si_gpu_max_clock_frequency;
  break;
 case 0x100d:
  size_ret = 4;
  info = &si_gpu_address_bits;
  break;
 case 0x100e:
  size_ret = 4;
  info = &si_gpu_max_read_image_args;
  break;
 case 0x100f:
  size_ret = 4;
  info = &si_gpu_max_write_image_args;
  break;
 case 0x1010:
  size_ret = 8;
  info = &si_gpu_max_mem_alloc_size;
  break;
 case 0x1011:
  size_ret = 4;
  info = &si_gpu_image2d_max_width;
  break;
 case 0x1012:
  size_ret = 4;
  info = &si_gpu_image2d_max_height;
  break;
 case 0x1013:
  size_ret = 4;
  info = &si_gpu_image3d_max_width;
  break;
 case 0x1014:
  size_ret = 4;
  info = &si_gpu_image3d_max_height;
  break;
 case 0x1015:
  size_ret = 4;
  info = &si_gpu_image3d_max_depth;
  break;
 case 0x1016:
  size_ret = 4;
  info = &si_gpu_image_support;
  break;
 case 0x1017:
  size_ret = 4;
  info = &si_gpu_max_parameter_size;
  break;
 case 0x1018:
  size_ret = 4;
  info = &si_gpu_max_samplers;
  break;
 case 0x1019:
  size_ret = 4;
  info = &si_gpu_mem_base_addr_align;
  break;
 case 0x101a:
  size_ret = 4;
  info = &si_gpu_min_data_type_align_size;
  break;
 case 0x101b:
  size_ret = 4;
  info = &si_gpu_single_fp_config;
  break;
 case 0x101c:
  size_ret = 4;
  info = &si_gpu_global_mem_cache_type;
  break;
 case 0x101d:
  size_ret = 4;
  info = &si_gpu_global_mem_cacheline_size;
  break;
 case 0x101e:
  size_ret = 8;
  info = &si_gpu_global_mem_cache_size;
  break;
 case 0x101f:
  size_ret = 8;
  info = &si_gpu_global_mem_size;
  break;
 case 0x1020:
  size_ret = 8;
  info = &si_gpu_max_constant_buffer_size;
  break;
 case 0x1021:
  size_ret = 4;
  info = &si_gpu_max_constant_args;
  break;
 case 0x1022:
  size_ret = 4;
  info = &si_gpu_local_mem_type;
  break;
 case 0x1023:
  size_ret = 8;
  info = &si_gpu_local_mem_size;
  break;
 case 0x1024:
  size_ret = 4;
  info = &si_gpu_error_correction_support;
  break;
 case 0x1025:
  size_ret = 4;
  info = &si_gpu_profiling_timer_resolution;
  break;
 case 0x1026:
  size_ret = 4;
  info = &si_gpu_endian_little;
  break;
 case 0x1027:
  size_ret = 4;
  info = &si_gpu_device_available;
  break;
 case 0x1028:
  size_ret = 4;
  info = &si_gpu_compiler_available;
  break;
 case 0x1029:
  size_ret = 4;
  info = &si_gpu_execution_capabilities;
  break;
 case 0x102a:
  size_ret = 4;
  info = &si_gpu_queue_properties;
  break;
 case 0x102b:
  size_ret = strlen(si_gpu_device_name) + 1;
  info = si_gpu_device_name;
  break;
 case 0x102c:
  size_ret = strlen(si_gpu_device_vendor) + 1;
  info = si_gpu_device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(si_gpu_driver_version) + 1;
  info = si_gpu_driver_version;
  break;
 case 0x102e:
  size_ret = strlen(si_gpu_device_profile) + 1;
  info = si_gpu_device_profile;
  break;
 case 0x102f:
  size_ret = strlen(si_gpu_device_version) + 1;
  info = si_gpu_device_version;
  break;
 case 0x1030:
  size_ret = strlen(si_gpu_device_extensions) + 1;
  info = si_gpu_device_extensions;
  break;
 case 0x1031:
  size_ret = 4;
  info = &si_gpu_platform;
  break;
 case 0x1032:
  size_ret = 4;
  info = &si_gpu_double_fp_config;
  break;
 case 0x1034:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x1035:
  size_ret = 4;
  info = &si_gpu_host_unified_memory;
  break;
 case 0x1036:
 case 0x1037:
 case 0x1038:
 case 0x1039:
 case 0x103a:
 case 0x103b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x103c:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x103d:
  size_ret = strlen(si_gpu_opencl_version) + 1;
  info = si_gpu_opencl_version;
  break;
 case 0x103e:
  size_ret = 4;
  info = &si_gpu_linker_available;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 343, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int si_opencl_device_get_info(struct si_opencl_device_t *device, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 unsigned int size_ret = 0;
 void *info = ((void *)0);
 switch (name)
 {
 case 0x1000:
  size_ret = 4;
  info = &si_gpu_device_type;
  break;
 case 0x1001:
  size_ret = 4;
  info = &si_gpu_device_vendor_id;
  break;
 case 0x1002:
  size_ret = 4;
  info = &si_gpu_num_compute_units;
  break;
 case 0x1003:
  size_ret = 4;
  info = &si_gpu_work_item_dimensions;
  break;
 case 0x1004:
  size_ret = 4;
  info = &si_gpu_work_group_size;
  break;
 case 0x1005:
  size_ret = 12;
  info = si_gpu_work_item_sizes;
  break;
 case 0x1006:
 case 0x1007:
 case 0x1008:
 case 0x1009:
 case 0x100a:
 case 0x100b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x100c:
  size_ret = 4;
  info = &si_gpu_max_clock_frequency;
  break;
 case 0x100d:
  size_ret = 4;
  info = &si_gpu_address_bits;
  break;
 case 0x100e:
  size_ret = 4;
  info = &si_gpu_max_read_image_args;
  break;
 case 0x100f:
  size_ret = 4;
  info = &si_gpu_max_write_image_args;
  break;
 case 0x1010:
  size_ret = 8;
  info = &si_gpu_max_mem_alloc_size;
  break;
 case 0x1011:
  size_ret = 4;
  info = &si_gpu_image2d_max_width;
  break;
 case 0x1012:
  size_ret = 4;
  info = &si_gpu_image2d_max_height;
  break;
 case 0x1013:
  size_ret = 4;
  info = &si_gpu_image3d_max_width;
  break;
 case 0x1014:
  size_ret = 4;
  info = &si_gpu_image3d_max_height;
  break;
 case 0x1015:
  size_ret = 4;
  info = &si_gpu_image3d_max_depth;
  break;
 case 0x1016:
  size_ret = 4;
  info = &si_gpu_image_support;
  break;
 case 0x1017:
  size_ret = 4;
  info = &si_gpu_max_parameter_size;
  break;
 case 0x1018:
  size_ret = 4;
  info = &si_gpu_max_samplers;
  break;
 case 0x1019:
  size_ret = 4;
  info = &si_gpu_mem_base_addr_align;
  break;
 case 0x101a:
  size_ret = 4;
  info = &si_gpu_min_data_type_align_size;
  break;
 case 0x101b:
  size_ret = 4;
  info = &si_gpu_single_fp_config;
  break;
 case 0x101c:
  size_ret = 4;
  info = &si_gpu_global_mem_cache_type;
  break;
 case 0x101d:
  size_ret = 4;
  info = &si_gpu_global_mem_cacheline_size;
  break;
 case 0x101e:
  size_ret = 8;
  info = &si_gpu_global_mem_cache_size;
  break;
 case 0x101f:
  size_ret = 8;
  info = &si_gpu_global_mem_size;
  break;
 case 0x1020:
  size_ret = 8;
  info = &si_gpu_max_constant_buffer_size;
  break;
 case 0x1021:
  size_ret = 4;
  info = &si_gpu_max_constant_args;
  break;
 case 0x1022:
  size_ret = 4;
  info = &si_gpu_local_mem_type;
  break;
 case 0x1023:
  size_ret = 8;
  info = &si_gpu_local_mem_size;
  break;
 case 0x1024:
  size_ret = 4;
  info = &si_gpu_error_correction_support;
  break;
 case 0x1025:
  size_ret = 4;
  info = &si_gpu_profiling_timer_resolution;
  break;
 case 0x1026:
  size_ret = 4;
  info = &si_gpu_endian_little;
  break;
 case 0x1027:
  size_ret = 4;
  info = &si_gpu_device_available;
  break;
 case 0x1028:
  size_ret = 4;
  info = &si_gpu_compiler_available;
  break;
 case 0x1029:
  size_ret = 4;
  info = &si_gpu_execution_capabilities;
  break;
 case 0x102a:
  size_ret = 4;
  info = &si_gpu_queue_properties;
  break;
 case 0x102b:
  size_ret = strlen(si_gpu_device_name) + 1;
  info = si_gpu_device_name;
  break;
 case 0x102c:
  size_ret = strlen(si_gpu_device_vendor) + 1;
  info = si_gpu_device_vendor;
  break;
 case 0x102d:
  size_ret = strlen(si_gpu_driver_version) + 1;
  info = si_gpu_driver_version;
  break;
 case 0x102e:
  size_ret = strlen(si_gpu_device_profile) + 1;
  info = si_gpu_device_profile;
  break;
 case 0x102f:
  size_ret = strlen(si_gpu_device_version) + 1;
  info = si_gpu_device_version;
  break;
 case 0x1030:
  size_ret = strlen(si_gpu_device_extensions) + 1;
  info = si_gpu_device_extensions;
  break;
 case 0x1031:
  size_ret = 4;
  info = &si_gpu_platform;
  break;
 case 0x1032:
  size_ret = 4;
  info = &si_gpu_double_fp_config;
  break;
 case 0x1034:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x1035:
  size_ret = 4;
  info = &si_gpu_host_unified_memory;
  break;
 case 0x1036:
 case 0x1037:
 case 0x1038:
 case 0x1039:
 case 0x103a:
 case 0x103b:
  size_ret = 4;
  info = &si_gpu_num_stream_cores;
  break;
 case 0x103c:
  size_ret = 4;
  info = &si_gpu_vector_width_half;
  break;
 case 0x103d:
  size_ret = strlen(si_gpu_opencl_version) + 1;
  info = si_gpu_opencl_version;
  break;
 case 0x103e:
  size_ret = 4;
  info = &si_gpu_linker_available;
  break;
 default:
  fatal("opencl_device_get_info: invalid or not implemented value for 'name' (0x%x)\n%s",
   name, si_err_opencl_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-device.c", 343, __extension__ __PRETTY_FUNCTION__); }));
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
name
unsigned int

variable_types: struct mem_t { int num_links; struct mem_page_t { unsigned int tag; enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 } perm; struct mem_page_t *next; unsigned char *data; } *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; } *

variable_types:
addr
unsigned int

variable_types:
size
unsigned int

variable_types:
info
void *

return_type: unsigned int

user_defined_types: struct mem_t { int num_links; struct mem_page_t *pages[1024]; int safe; unsigned int heap_break; unsigned int last_address; }

user_defined_types: struct mem_page_t { unsigned int tag; enum mem_access_t perm; struct mem_page_t *next; unsigned char *data; }


decompiled_code:
__int64 x86_glut_missing()
{
return fatal(
"support for GLUT not available.\n"
"\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
"\tinstalled in your system to simulate OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

canonical_decompiled_code:
__int64 func0()
{
return fatal(
"support for GLUT not available.\n"
"\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
"\tinstalled in your system to simulate OpenGL programs.\n"
"\t 1) Install the development packages for GLUT. Under Debian-based\n"
"\t Linux distributions, this package is listed as 'freeglut3-dev'.\n"
"\t 2) Re-run the './configure' script\n"
"\t 3) Recompile the simulator: make clean && make\n");
}

original_code:
static void x86_glut_missing(void)
{
 fatal("support for GLUT not available.\n"
  "\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
  "\tinstalled in your system to simulate OpenGL programs.\n"
  "\t  1) Install the development packages for GLUT. Under Debian-based\n"
  "\t     Linux distributions, this package is listed as 'freeglut3-dev'.\n"
  "\t  2) Re-run the './configure' script\n"
  "\t  3) Recompile the simulator: make clean && make\n");
}

canonical_original_code:
static void x86_glut_missing()
{
 fatal("support for GLUT not available.\n"
  "\tMulti2Sim requires the OpenGL Utility Toolkit (GLUT) library to be\n"
  "\tinstalled in your system to simulate OpenGL programs.\n"
  "\t  1) Install the development packages for GLUT. Under Debian-based\n"
  "\t     Linux distributions, this package is listed as 'freeglut3-dev'.\n"
  "\t  2) Re-run the './configure' script\n"
  "\t  3) Recompile the simulator: make clean && make\n");
}

return_type: void


decompiled_code:
void x86_glut_init()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void x86_glut_init(void)
{
}

canonical_original_code:
void x86_glut_init()
{
}


decompiled_code:
void x86_glut_done()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void x86_glut_done(void)
{
}

canonical_original_code:
void x86_glut_done()
{
}


decompiled_code:
void x86_glut_frame_buffer_init()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void x86_glut_frame_buffer_init(void)
{
}

canonical_original_code:
void x86_glut_frame_buffer_init()
{
}


decompiled_code:
void x86_glut_frame_buffer_done()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void x86_glut_frame_buffer_done(void)
{
}

canonical_original_code:
void x86_glut_frame_buffer_done()
{
}


decompiled_code:
__int64 x86_glut_frame_buffer_clear()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func6()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_clear(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_clear()
{
 x86_glut_missing();
}


decompiled_code:
__int64 x86_glut_frame_buffer_pixel()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func7()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_pixel(int x, int y, int color)
{
 x86_glut_missing();
}

variable_types: x int

variable_types: y int

variable_types: color int


decompiled_code:
__int64 x86_glut_frame_buffer_resize()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func8()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_resize(int width, int height)
{
 x86_glut_missing();
}

variable_types: width int

variable_types: height int


decompiled_code:
__int64 x86_glut_frame_buffer_get_size()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func9()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_get_size(int *width, int *height)
{
 x86_glut_missing();
}

variable_types:
width
int *

variable_types:
height
int *


decompiled_code:
__int64 x86_glut_frame_buffer_flush_request()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func10()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_flush_request(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_flush_request()
{
 x86_glut_missing();
}


decompiled_code:
__int64 x86_glut_frame_buffer_flush_if_requested()
{
return x86_glut_missing();
}

canonical_decompiled_code:
__int64 func11()
{
return func0();
}

original_code:
void x86_glut_frame_buffer_flush_if_requested(void)
{
 x86_glut_missing();
}

canonical_original_code:
void x86_glut_frame_buffer_flush_if_requested()
{
 x86_glut_missing();
}


decompiled_code:
__int64 x86_regs_create()
{
return mhandle_calloc(1LL, 318LL, "regs.c:26");
}

canonical_decompiled_code:
__int64 func0()
{
return mhandle_calloc(1LL, 318LL, "regs.c:26");
}

original_code:
struct x86_regs_t *x86_regs_create()
{
 struct x86_regs_t *regs;
 regs = (mhandle_calloc(1, sizeof(struct x86_regs_t), "regs.c" ":" "26"));
 return regs;
}

variable_types: struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; } *


decompiled_code:
__int64 __fastcall x86_regs_free(__int64 a1)
{
return mhandle_free(a1, "regs.c:33");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return mhandle_free(a1, "regs.c:33");
}

original_code:
void x86_regs_free(struct x86_regs_t *regs)
{
 (mhandle_free(regs, "regs.c" ":" "33"));
}

user_defined_types: struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; }


decompiled_code:
__int64 __fastcall x86_regs_copy(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

*a1 = *a2;
result = *(_QWORD *)((char *)a2 + 310);
*(_QWORD *)((char *)a1 + 310) = result;
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 318) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax

*a1 = *a2;
result = *(_QWORD *)((char *)a2 + 310);
*(_QWORD *)((char *)a1 + 310) = result;
qmemcpy(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)a2 - ((char *)a1 - ((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 318) >> 3));
return result;
}

original_code:
void x86_regs_copy(struct x86_regs_t *dst, struct x86_regs_t *src)
{
 memcpy(dst, src, sizeof(struct x86_regs_t));
}

variable_types:
src
struct x86_regs_t *


decompiled_code:
_DWORD *evg_opencl_platform_create()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-platform.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_platform_create");
*v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 1LL);
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rbx

v0 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opencl-platform.c:34");
if ( !v0 )
fatal("%s: out of memory", "evg_opencl_platform_create");
*v0 = evg_opencl_repo_new_object_id(*(_QWORD *)(evg_emu + 8LL), 1LL);
evg_opencl_repo_add_object(*(_QWORD *)(evg_emu + 8LL), v0);
return v0;
}

original_code:
struct evg_opencl_platform_t *evg_opencl_platform_create()
{
 struct evg_opencl_platform_t *platform;
 platform = (mhandle_calloc(1, sizeof(struct evg_opencl_platform_t), "opencl-platform.c" ":" "34"));
 if (!platform)
  fatal("%s: out of memory", __FUNCTION__);
 platform->id = evg_opencl_repo_new_object_id(evg_emu->opencl_repo,
  evg_opencl_object_platform);
 evg_opencl_repo_add_object(evg_emu->opencl_repo, platform);
 return platform;
}

variable_types: struct evg_opencl_platform_t { unsigned int id; } *


decompiled_code:
__int64 __fastcall evg_opencl_platform_free(__int64 a1)
{
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-platform.c:51");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
evg_opencl_repo_remove_object(*(_QWORD *)(evg_emu + 8LL), a1);
return mhandle_free(a1, "opencl-platform.c:51");
}

original_code:
void evg_opencl_platform_free(struct evg_opencl_platform_t *platform)
{
 evg_opencl_repo_remove_object(evg_emu->opencl_repo, platform);
 (mhandle_free(platform, "opencl-platform.c" ":" "51"));
}

user_defined_types: struct evg_opencl_platform_t { unsigned int id; }


decompiled_code:
__int64 __fastcall evg_opencl_platform_get_info(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
const char *v8; // r14
unsigned int v9; // ebx

switch ( (int)a2 )
{
case 2304:
v8 = "FULL_PROFILE";
break;
case 2305:
v8 = "OpenCL 1.1 Multi2Sim-v4.0";
break;
case 2306:
v8 = "Multi2Sim";
break;
case 2307:
v8 = "www.multi2sim.org";
break;
case 2308:
v8 = (const char *)&unk_16F;
break;
default:
fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s", a2, evg_err_opencl_param_note);
_assert_fail("info", "opencl-platform.c", 0x5Fu, "evg_opencl_platform_get_info");
}
v9 = strlen(v8) + 1;
if ( a4 && v9 <= a5 )
mem_write(a3, a4, v9, v8);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5)
{
const char *v8; // r14
unsigned int v9; // ebx

switch ( (int)a2 )
{
case 2304:
v8 = "FULL_PROFILE";
break;
case 2305:
v8 = "OpenCL 1.1 Multi2Sim-v4.0";
break;
case 2306:
v8 = "Multi2Sim";
break;
case 2307:
v8 = "www.multi2sim.org";
break;
case 2308:
v8 = (const char *)&unk_16F;
break;
default:
fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s", a2, evg_err_opencl_param_note);
_assert_fail("info", "opencl-platform.c", 0x5Fu, "evg_opencl_platform_get_info");
}
v9 = strlen(v8) + 1;
if ( a4 && v9 <= a5 )
mem_write(a3, a4, v9, v8);
return v9;
}

original_code:
uint32_t evg_opencl_platform_get_info(struct evg_opencl_platform_t *platform, uint32_t name, struct mem_t *mem, uint32_t addr, uint32_t size)
{
 char *platform_profile = "FULL_PROFILE";
 char *platform_version = "OpenCL 1.1 Multi2Sim-v" "4.0";
 char *platform_name = "Multi2Sim";
 char *platform_vendor = "www.multi2sim.org";
 char *platform_extensions = "";
 uint32_t size_ret = 0;
 char *info;
 switch (name) {
 case 0x900:
  info = platform_profile;
  break;
 case 0x901:
  info = platform_version;
  break;
 case 0x902:
  info = platform_name;
  break;
 case 0x903:
  info = platform_vendor;
  break;
 case 0x904:
  info = platform_extensions;
  break;
 default:
  info = ((void *)0);
  fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-platform.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 size_ret = strlen(info) + 1;
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

canonical_original_code:
unsigned int evg_opencl_platform_get_info(struct evg_opencl_platform_t *platform, unsigned int name, struct mem_t *mem, unsigned int addr, unsigned int size)
{
 char *platform_profile = "FULL_PROFILE";
 char *platform_version = "OpenCL 1.1 Multi2Sim-v" "4.0";
 char *platform_name = "Multi2Sim";
 char *platform_vendor = "www.multi2sim.org";
 char *platform_extensions = "";
 unsigned int size_ret = 0;
 char *info;
 switch (name) {
 case 0x900:
  info = platform_profile;
  break;
 case 0x901:
  info = platform_version;
  break;
 case 0x902:
  info = platform_name;
  break;
 case 0x903:
  info = platform_vendor;
  break;
 case 0x904:
  info = platform_extensions;
  break;
 default:
  info = ((void *)0);
  fatal("opencl_platform_get_info: invalid value for 'name' (0x%x)\n%s",
   name, evg_err_opencl_param_note);
 }
 ((void) sizeof ((info) ? 1 : 0), __extension__ ({ if (info) ; else __assert_fail ("info", "opencl-platform.c", 95, __extension__ __PRETTY_FUNCTION__); }));
 size_ret = strlen(info) + 1;
 if (addr && size >= size_ret)
  mem_write(mem, addr, size_ret, info);
 return size_ret;
}

variable_types:
info
char *

user_defined_types: enum mem_access_t { mem_access_none=0, mem_access_read=1, mem_access_write=2, mem_access_exec=4, mem_access_init=8, mem_access_modif=16 }


decompiled_code:
__int64 __fastcall sim_signal_name(unsigned int a1)
{
return map_value(&signal_map, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return map_value(&signal_map, a1);
}

original_code:
char *sim_signal_name(int signum)
{
 return map_value(&signal_map, signum);
}

variable_types: signum int

return_type: char *


decompiled_code:
__int64 __fastcall sim_sigset_member(_QWORD *a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( (unsigned int)(a2 - 1) <= 0x3F )
result = (*a1 >> ((unsigned __int8)a2 - 1)) & 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, int a2)
{
__int64 result; // rax

result = 0LL;
if ( (unsigned int)(a2 - 1) <= 0x3F )
result = (*a1 >> ((unsigned __int8)a2 - 1)) & 1LL;
return result;
}

original_code:
int sim_sigset_member(unsigned long long *sim_sigset, int sig)
{
 if (sig < 1 || sig > 64)
  return 0;
 return (*sim_sigset & (1ULL << (sig - 1))) > 0;
}

variable_types: sig int

return_type: int


decompiled_code:
__int64 signal_mask_table_create()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 40LL, "signal.c:167");
if ( !v0 )
fatal("%s: out of memory", "signal_mask_table_create");
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 40LL, "signal.c:167");
if ( !v0 )
fatal("%s: out of memory", "signal_mask_table_create");
return v0;
}

original_code:
struct signal_mask_table_t *signal_mask_table_create(void)
{
 struct signal_mask_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_mask_table_t), "signal.c" ":" "167"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

canonical_original_code:
struct signal_mask_table_t *signal_mask_table_create()
{
 struct signal_mask_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_mask_table_t), "signal.c" ":" "167"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

variable_types: struct signal_mask_table_t { unsigned long long pending; unsigned long long blocked; unsigned long long backup; struct x86_regs_t { unsigned int eax; unsigned int esp; unsigned short es; unsigned int eip; unsigned int eflags; struct { unsigned char value[10]; int valid; } fpu_stack[8]; int fpu_top; int fpu_code; unsigned short fpu_ctrl; unsigned char xmm[8][16]; } *regs; unsigned int pretcode; } *

user_defined_types: struct signal_mask_table_t { unsigned long long pending; unsigned long long blocked; unsigned long long backup; struct x86_regs_t *regs; unsigned int pretcode; }


decompiled_code:
__int64 __fastcall signal_mask_table_free(__int64 a1)
{
return mhandle_free(a1, "signal.c:177");
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return mhandle_free(a1, "signal.c:177");
}

original_code:
void signal_mask_table_free(struct signal_mask_table_t *table)
{
 (mhandle_free(table, "signal.c" ":" "177"));
}


decompiled_code:
__int64 signal_handler_table_create()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 1544LL, "signal.c:192");
if ( !v0 )
fatal("%s: out of memory", "signal_handler_table_create");
return v0;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 1544LL, "signal.c:192");
if ( !v0 )
fatal("%s: out of memory", "signal_handler_table_create");
return v0;
}

original_code:
struct signal_handler_table_t *signal_handler_table_create(void)
{
 struct signal_handler_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_handler_table_t), "signal.c" ":" "192"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

canonical_original_code:
struct signal_handler_table_t *signal_handler_table_create()
{
 struct signal_handler_table_t *table;
 table = (mhandle_calloc(1, sizeof(struct signal_handler_table_t), "signal.c" ":" "192"));
 if (!table)
  fatal("%s: out of memory", __FUNCTION__);
 return table;
}

variable_types: struct signal_handler_table_t { int num_links; struct sim_sigaction { unsigned int handler; unsigned int flags; unsigned int restorer; unsigned long long mask; } sigaction[64]; } *

user_defined_types: struct signal_handler_table_t { int num_links; struct sim_sigaction sigaction[64]; }


decompiled_code:
__int64 __fastcall signal_handler_table_free(_DWORD *a1)
{
if ( *a1 )
_assert_fail("!table->num_links", "signal.c", 0xCBu, "signal_handler_table_free");
return mhandle_free(a1, "signal.c:204");
}

canonical_decompiled_code:
__int64 __fastcall func10(_DWORD *a1)
{
if ( *a1 )
_assert_fail("!table->num_links", "signal.c", 0xCBu, "signal_handler_table_free");
return mhandle_free(a1, "signal.c:204");
}

original_code:
void signal_handler_table_free(struct signal_handler_table_t *table)
{
 ((void) sizeof ((!table->num_links) ? 1 : 0), __extension__ ({ if (!table->num_links) ; else __assert_fail ("!table->num_links", "signal.c", 203, __extension__ __PRETTY_FUNCTION__); }));
 (mhandle_free(table, "signal.c" ":" "204"));
}

user_defined_types: struct sim_sigaction { unsigned int handler; unsigned int flags; unsigned int restorer; unsigned long long mask; }


decompiled_code:
__int64 __fastcall signal_handler_table_unlink(int *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("table->num_links >= 0", "signal.c", 0xD9u, "signal_handler_table_unlink");
if ( !v1 )
return signal_handler_table_free(a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1)
{
int v1; // eax
__int64 result; // rax

v1 = *a1;
if ( *a1 < 0 )
_assert_fail("table->num_links >= 0", "signal.c", 0xD9u, "signal_handler_table_unlink");
if ( !v1 )
return func10(a1);
result = (unsigned int)(v1 - 1);
*a1 = result;
return result;
}

original_code:
void signal_handler_table_unlink(struct signal_handler_table_t *table)
{
 ((void) sizeof ((table->num_links >= 0) ? 1 : 0), __extension__ ({ if (table->num_links >= 0) ; else __assert_fail ("table->num_links >= 0", "signal.c", 217, __extension__ __PRETTY_FUNCTION__); }));
 if (table->num_links)
  table->num_links--;
 else
  signal_handler_table_free(table);
}


decompiled_code:
__suseconds_t m2s_timer_now()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

canonical_decompiled_code:
__suseconds_t func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return v1.tv_usec + 1000000 * v1.tv_sec;
}

original_code:
static long long m2s_timer_now(void)
{
 struct timeval tv;
 long long value;
 gettimeofday(&tv, ((void *)0));
 value = (long long) tv.tv_sec * 1000000 + tv.tv_usec;
 return value;
}

canonical_original_code:
static long long m2s_timer_now()
{
 struct timeval tv;
 long long value;
 gettimeofday(&tv, ((void *)0));
 value = (long long) tv.tv_sec * 1000000 + tv.tv_usec;
 return value;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
value
long long

return_type: long long


decompiled_code:
__int64 __fastcall m2s_timer_create(void *a1)
{
void *v1; // rbp
__int64 v2; // rbx
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "timer.c:74");
if ( !v2 )
fatal("%s: out of memory", "m2s_timer_create");
*(_DWORD *)(v2 + 8) = 1;
if ( !a1 )
v1 = &unk_13F;
v3 = mhandle_strdup(v1, "timer.c:80");
*(_QWORD *)v2 = v3;
if ( !v3 )
fatal("%s: out of memory", "m2s_timer_create");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
void *v1; // rbp
__int64 v2; // rbx
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "timer.c:74");
if ( !v2 )
fatal("%s: out of memory", "m2s_timer_create");
*(_DWORD *)(v2 + 8) = 1;
if ( !a1 )
v1 = &unk_13F;
v3 = mhandle_strdup(v1, "timer.c:80");
*(_QWORD *)v2 = v3;
if ( !v3 )
fatal("%s: out of memory", "m2s_timer_create");
return v2;
}

original_code:
struct m2s_timer_t *m2s_timer_create(char *name)
{
 struct m2s_timer_t *timer;
 timer = (mhandle_calloc(1, sizeof(struct m2s_timer_t), "timer.c" ":" "74"));
 if (!timer)
  fatal("%s: out of memory", __FUNCTION__);
 timer->state = m2s_timer_state_stopped;
 timer->name = (mhandle_strdup(name ? name : "", "timer.c" ":" "80"));
 if (!timer->name)
  fatal("%s: out of memory", __FUNCTION__);
 return timer;
}

variable_types:
name
char *

variable_types: struct m2s_timer_t { char *name; enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 } state; long long start_value; long long total_value; } *

user_defined_types: struct m2s_timer_t { char *name; enum m2s_timer_state_t state; long long start_value; long long total_value; }


decompiled_code:
__int64 __fastcall m2s_timer_free(_QWORD *a1)
{
mhandle_free(*a1, "timer.c:91");
return mhandle_free(a1, "timer.c:92");
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
mhandle_free(*a1, "timer.c:91");
return mhandle_free(a1, "timer.c:92");
}

original_code:
void m2s_timer_free(struct m2s_timer_t *timer)
{
 (mhandle_free(timer->name, "timer.c" ":" "91"));
 (mhandle_free(timer, "timer.c" ":" "92"));
}

user_defined_types: enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 }


original_code:
void m2s_timer_start(struct m2s_timer_t *timer)
{
 if (timer->state == m2s_timer_state_running)
  return;
 timer->state = m2s_timer_state_running;
 timer->start_value = m2s_timer_now();
}


original_code:
void m2s_timer_stop(struct m2s_timer_t *timer)
{
 long long ellapsed;
 if (timer->state == m2s_timer_state_stopped)
  return;
 ellapsed = m2s_timer_now() - timer->start_value;
 timer->state = m2s_timer_state_stopped;
 timer->total_value += ellapsed;
}

variable_types:
ellapsed
long long


decompiled_code:
__suseconds_t __fastcall m2s_timer_reset(__int64 a1)
{
__suseconds_t result; // rax

*(_QWORD *)(a1 + 24) = 0LL;
result = m2s_timer_now();
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func5(__int64 a1)
{
__suseconds_t result; // rax

*(_QWORD *)(a1 + 24) = 0LL;
result = func0();
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void m2s_timer_reset(struct m2s_timer_t *timer)
{
 timer->total_value = 0;
 timer->start_value = m2s_timer_now();
}


decompiled_code:
__suseconds_t __fastcall m2s_timer_get_value(__int64 a1)
{
__suseconds_t result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 24) + m2s_timer_now() - *(_QWORD *)(a1 + 16);
return result;
}

canonical_decompiled_code:
__suseconds_t __fastcall func6(__int64 a1)
{
__suseconds_t result; // rax

if ( *(_DWORD *)(a1 + 8) == 1 )
result = *(_QWORD *)(a1 + 24);
else
result = *(_QWORD *)(a1 + 24) + func0() - *(_QWORD *)(a1 + 16);
return result;
}

original_code:
long long m2s_timer_get_value(struct m2s_timer_t *timer)
{
 long long ellapsed;
 if (timer->state == m2s_timer_state_stopped)
  return timer->total_value;
 ellapsed = m2s_timer_now() - timer->start_value;
 return timer->total_value + ellapsed;
}


decompiled_code:
__int64 __fastcall m2s_timer_get_state(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
enum m2s_timer_state_t m2s_timer_get_state(struct m2s_timer_t *timer)
{
 return timer->state;
}

return_type: enum m2s_timer_state_t { m2s_timer_state_invalid=0, m2s_timer_state_stopped=1, m2s_timer_state_running=2 }


decompiled_code:
__int64 __fastcall m2s_timer_get_name(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
char *m2s_timer_get_name(struct m2s_timer_t *timer)
{
 return timer->name;
}


original_code:
static void mark_corruption(void *ptr, unsigned long size)
{
 unsigned long i;
 for (i = 0; i < 2; i++)
  ((unsigned char *) ptr)[i] = 0x5a;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  ((unsigned char *) ptr)[i] = 0xa5;
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

variable_types:
i
unsigned long


outofmem

decompiled_code:
void __fastcall __noreturn outofmem(const char *a1)
{
fprintf(stderr, "\nfatal: %s: out of memory\n", a1);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "\nfatal: %s: out of memory\n", a1);
abort();
}

original_code:
static void outofmem(char *at)
{
 fprintf(stderr, "\nfatal: %s: out of memory\n", at);
 abort();
}

variable_types:
at
char *


initialize

decompiled_code:
void initialize()
{
if ( !initialized )
{
initialized = 1;
ht = calloc(0x3E8uLL, 0x20uLL);
ht_size = 1000;
ht_count = 0;
if ( !ht )
outofmem("lib mhandle (initialize)");
}
}

canonical_decompiled_code:
void func2()
{
if ( !initialized )
{
initialized = 1;
ht = calloc(0x3E8uLL, 0x20uLL);
ht_size = 1000;
ht_count = 0;
if ( !ht )
func1("lib mhandle (initialize)");
}
}

original_code:
static void initialize()
{
 if (initialized)
  return;
 initialized = 1;
 ht = (struct item_t *) calloc(1000, sizeof(struct item_t));
 ht_size = 1000;
 ht_count = 0;
 if (!ht)
  outofmem("lib mhandle (initialize)");
}

user_defined_types: struct item_t { void *ptr; unsigned long size; char *at; int removed; int active; }


decompiled_code:
void ht_grow()
{
int v0; // ebp
_QWORD *v1; // r12
_QWORD *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v0 = ht_size;
v1 = ht;
ht_size *= 2;
ht = calloc(ht_size, 0x20uLL);
if ( !ht )
outofmem("lib mhandle (resizing hash table)");
if ( v0 > 0 )
{
v2 = v1;
v3 = (__int64)&v1[4 * (unsigned int)(v0 - 1) + 4];
do
{
if ( (v2[3] & 3) == 2 )
{
--ht_count;
v4 = v2[1];
mem_busy -= v4;
ht_insert(*v2, v4, v2[2]);
}
v2 += 4;
}
while ( v2 != (_QWORD *)v3 );
}
free(v1);
}

canonical_decompiled_code:
void func3()
{
int v0; // ebp
_QWORD *v1; // r12
_QWORD *v2; // rbx
__int64 v3; // rbp
__int64 v4; // rsi

v0 = ht_size;
v1 = ht;
ht_size *= 2;
ht = calloc(ht_size, 0x20uLL);
if ( !ht )
func1("lib mhandle (resizing hash table)");
if ( v0 > 0 )
{
v2 = v1;
v3 = (__int64)&v1[4 * (unsigned int)(v0 - 1) + 4];
do
{
if ( (v2[3] & 3) == 2 )
{
--ht_count;
v4 = v2[1];
mem_busy -= v4;
func4(*v2, v4, v2[2]);
}
v2 += 4;
}
while ( v2 != (_QWORD *)v3 );
}
free(v1);
}

original_code:
static void ht_grow()
{
 int old_size, i;
 struct item_t *old_ht;
 old_size = ht_size;
 old_ht = ht;
 ht_size = ht_size * 2;
 ht = (struct item_t *) calloc(ht_size, sizeof(struct item_t));
 if (!ht)
  outofmem("lib mhandle (resizing hash table)");
 for (i = 0; i < old_size; i++) {
  if (old_ht[i].active && !old_ht[i].removed) {
   ht_count--;
   mem_busy -= old_ht[i].size;
   ht_insert(old_ht[i].ptr, old_ht[i].size, old_ht[i].at);
  }
 }
 free(old_ht);
}

canonical_original_code:
static void ht_grow()
{
 int old_size; int i;
 struct item_t *old_ht;
 old_size = ht_size;
 old_ht = ht;
 ht_size = ht_size * 2;
 ht = (struct item_t *) calloc(ht_size, sizeof(struct item_t));
 if (!ht)
  outofmem("lib mhandle (resizing hash table)");
 for (i = 0; i < old_size; i++) {
  if (old_ht[i].active && !old_ht[i].removed) {
   ht_count--;
   mem_busy -= old_ht[i].size;
   ht_insert(old_ht[i].ptr, old_ht[i].size, old_ht[i].at);
  }
 }
 free(old_ht);
}

variable_types: i int

variable_types: struct item_t { void *ptr; unsigned long size; char *at; int removed; int active; } *


decompiled_code:
__int64 __fastcall ht_insert(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v4; // eax
char *i; // rdx
__int64 result; // rax

if ( ht_size / 2 <= ht_count )
ht_grow();
v4 = a1 % ht_size;
for ( i = (char *)ht + 32 * v4; (i[24] & 3) == 2; i = (char *)ht + 32 * v4 )
v4 = (v4 + 1) % ht_size;
*(_QWORD *)i = a1;
*((_QWORD *)i + 1) = a2;
*((_QWORD *)i + 2) = a3;
result = ((unsigned __int8)i[24] | 2) & 0xFE;
i[24] = (i[24] | 2) & 0xFE;
mem_busy += a2;
++ht_count;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, __int64 a2, __int64 a3)
{
int v4; // eax
char *i; // rdx
__int64 result; // rax

if ( ht_size / 2 <= ht_count )
func3();
v4 = a1 % ht_size;
for ( i = (char *)ht + 32 * v4; (i[24] & 3) == 2; i = (char *)ht + 32 * v4 )
v4 = (v4 + 1) % ht_size;
*(_QWORD *)i = a1;
*((_QWORD *)i + 1) = a2;
*((_QWORD *)i + 2) = a3;
result = ((unsigned __int8)i[24] | 2) & 0xFE;
i[24] = (i[24] | 2) & 0xFE;
mem_busy += a2;
++ht_count;
return result;
}

original_code:
static void ht_insert(void *ptr, unsigned long size, char *at)
{
 int idx;
 if (ht_count >= ht_size / 2)
  ht_grow();
 idx = (unsigned long) ptr % ht_size;
 while (ht[idx].active && !ht[idx].removed)
  idx = (idx + 1) % ht_size;
 ht[idx].ptr = ptr;
 ht[idx].size = size;
 ht[idx].at = at;
 ht[idx].active = 1;
 ht[idx].removed = 0;
 mem_busy += size;
 ht_count++;
}

variable_types: idx int


decompiled_code:
__int64 __fastcall check_corruption(_BYTE *a1, __int64 a2, const char *a3)
{
__int64 result; // rax
__int64 v5; // rdx
int v6; // ebx
__int64 v7; // rdx
char *v8; // rcx
unsigned __int64 v9; // rsi
int v10; // ebp
const char *v11; // rcx

LOBYTE(result) = *a1 != 90;
if ( a1[1] == 90 )
{
result = (unsigned __int8)result;
v5 = a2 + 2;
if ( a2 + 2 >= (unsigned __int64)(a2 + 4) )
goto LABEL_8;
}
else
{
v5 = a2 + 2;
if ( a2 + 2 >= (unsigned __int64)(a2 + 4) )
{
LODWORD(result) = 1;
LABEL_34:
if ( ht_size )
{
v8 = (char *)ht;
v6 = -1;
v10 = -1;
v7 = 0LL;
do
{
if ( (v8[24] & 3) == 2 )
{
v9 = *(_QWORD *)v8;
if ( *(_QWORD *)v8 < (unsigned __int64)a1 && (v10 == -1 || v9 > *((_QWORD *)ht + 4 * v10)) )
v10 = v7;
if ( v9 > (unsigned __int64)a1 && (v6 == -1 || v9 < *((_QWORD *)ht + 4 * v6)) )
v6 = v7;
}
++v7;
v8 += 32;
}
while ( v7 != ht_size );
v11 = "after";
if ( (_DWORD)result == 1 )
v11 = "before";
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, v11, a1);
if ( v10 >= 0 )
fprintf(stderr, "\tprev block: %s (%p)\n", *((const char **)ht + 4 * v10 + 2), *((const void **)ht + 4 * v10));
}
else
{
if ( (_DWORD)result == 1 )
{
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "before", a1);
goto LABEL_29;
}
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "after", a1);
v6 = -1;
}
if ( v6 >= 0 )
fprintf(stderr, "\tnext block: %s (%p)\n", *((const char **)ht + 4 * v6 + 2), *((const void **)ht + 4 * v6));
LABEL_29:
abort();
}
result = 1LL;
}
if ( a1[v5] != 0xA5 )
result = 2LL;
if ( a1[v5 + 1] != 0xA5 )
result = 2LL;
LABEL_8:
if ( (_DWORD)result )
goto LABEL_34;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1, __int64 a2, const char *a3)
{
__int64 result; // rax
__int64 v5; // rdx
int v6; // ebx
__int64 v7; // rdx
char *v8; // rcx
unsigned __int64 v9; // rsi
int v10; // ebp
const char *v11; // rcx

LOBYTE(result) = *a1 != 90;
if ( a1[1] == 90 )
{
result = (unsigned __int8)result;
v5 = a2 + 2;
if ( a2 + 2 >= (unsigned __int64)(a2 + 4) )
goto LABEL_8;
}
else
{
v5 = a2 + 2;
if ( a2 + 2 >= (unsigned __int64)(a2 + 4) )
{
LODWORD(result) = 1;
LABEL_34:
if ( ht_size )
{
v8 = (char *)ht;
v6 = -1;
v10 = -1;
v7 = 0LL;
do
{
if ( (v8[24] & 3) == 2 )
{
v9 = *(_QWORD *)v8;
if ( *(_QWORD *)v8 < (unsigned __int64)a1 && (v10 == -1 || v9 > *((_QWORD *)ht + 4 * v10)) )
v10 = v7;
if ( v9 > (unsigned __int64)a1 && (v6 == -1 || v9 < *((_QWORD *)ht + 4 * v6)) )
v6 = v7;
}
++v7;
v8 += 32;
}
while ( v7 != ht_size );
v11 = "after";
if ( (_DWORD)result == 1 )
v11 = "before";
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, v11, a1);
if ( v10 >= 0 )
fprintf(stderr, "\tprev block: %s (%p)\n", *((const char **)ht + 4 * v10 + 2), *((const void **)ht + 4 * v10));
}
else
{
if ( (_DWORD)result == 1 )
{
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "before", a1);
goto LABEL_29;
}
fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n", a3, "after", a1);
v6 = -1;
}
if ( v6 >= 0 )
fprintf(stderr, "\tnext block: %s (%p)\n", *((const char **)ht + 4 * v6 + 2), *((const void **)ht + 4 * v6));
LABEL_29:
abort();
}
result = 1LL;
}
if ( a1[v5] != 0xA5 )
result = 2LL;
if ( a1[v5 + 1] != 0xA5 )
result = 2LL;
LABEL_8:
if ( (_DWORD)result )
goto LABEL_34;
return result;
}

original_code:
static void check_corruption(void *ptr, unsigned long size, char *at)
{
 unsigned long i;
 int corrupt = 0, prev, next;
 for (i = 0; i < 2; i++)
  if (((unsigned char *) ptr)[i] != 0x5a)
   corrupt = 1;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  if (((unsigned char *) ptr)[i] != 0xa5)
   corrupt = 2;
 if (!corrupt)
  return;
 prev = next = -1;
 for (i = 0; i < ht_size; i++) {
  if (ht[i].active && !ht[i].removed) {
   if (ht[i].ptr < ptr && (prev == -1 || ht[i].ptr > ht[prev].ptr))
    prev = i;
   if (ht[i].ptr > ptr && (next == -1 || ht[i].ptr < ht[next].ptr))
    next = i;
  }
 }
 fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n",
  at, corrupt == 1 ? "before" : "after", ptr);
 if (prev >= 0)
  fprintf(stderr, "\tprev block: %s (%p)\n", ht[prev].at, ht[prev].ptr);
 if (next >= 0)
  fprintf(stderr, "\tnext block: %s (%p)\n", ht[next].at, ht[next].ptr);
 abort();
}

canonical_original_code:
static void check_corruption(void *ptr, unsigned long size, char *at)
{
 unsigned long i;
 int corrupt = 0; int prev; int next;
 for (i = 0; i < 2; i++)
  if (((unsigned char *) ptr)[i] != 0x5a)
   corrupt = 1;
 for (i = 2 + size; i < (2 * 2) + size; i++)
  if (((unsigned char *) ptr)[i] != 0xa5)
   corrupt = 2;
 if (!corrupt)
  return;
 prev = next = -1;
 for (i = 0; i < ht_size; i++) {
  if (ht[i].active && !ht[i].removed) {
   if (ht[i].ptr < ptr && (prev == -1 || ht[i].ptr > ht[prev].ptr))
    prev = i;
   if (ht[i].ptr > ptr && (next == -1 || ht[i].ptr < ht[next].ptr))
    next = i;
  }
 }
 fprintf(stderr, "\nfatal: %s: memory corrupted %s block (%p)\n",
  at, corrupt == 1 ? "before" : "after", ptr);
 if (prev >= 0)
  fprintf(stderr, "\tprev block: %s (%p)\n", ht[prev].at, ht[prev].ptr);
 if (next >= 0)
  fprintf(stderr, "\tnext block: %s (%p)\n", ht[next].at, ht[next].ptr);
 abort();
}

variable_types: corrupt int

variable_types: prev int

variable_types: next int


decompiled_code:
__int64 __fastcall ht_remove(unsigned __int64 a1, const char *a2)
{
unsigned __int64 i; // rdx
__int64 v3; // rbx
char *v4; // rcx
char *v5; // rbx
__int64 result; // rax

for ( i = a1 % ht_size; ; LODWORD(i) = ((int)i + 1) % ht_size )
{
v3 = 32LL * (int)i;
v4 = (char *)ht + v3;
if ( *(_QWORD *)((char *)ht + v3) == a1 && (v4[24] & 3) == 2 )
break;
if ( (v4[24] & 2) == 0 )
{
fprintf(stderr, "\n%s: free: invalid pointer %p\n", a2, (const void *)a1);
abort();
}
}
check_corruption((_BYTE *)a1, *((_QWORD *)v4 + 1), a2);
v5 = (char *)ht + v3;
v5[24] |= 1u;
result = *((_QWORD *)v5 + 1);
mem_busy -= result;
--ht_count;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int64 a1, const char *a2)
{
unsigned __int64 i; // rdx
__int64 v3; // rbx
char *v4; // rcx
char *v5; // rbx
__int64 result; // rax

for ( i = a1 % ht_size; ; LODWORD(i) = ((int)i + 1) % ht_size )
{
v3 = 32LL * (int)i;
v4 = (char *)ht + v3;
if ( *(_QWORD *)((char *)ht + v3) == a1 && (v4[24] & 3) == 2 )
break;
if ( (v4[24] & 2) == 0 )
{
fprintf(stderr, "\n%s: free: invalid pointer %p\n", a2, (const void *)a1);
abort();
}
}
func5((_BYTE *)a1, *((_QWORD *)v4 + 1), a2);
v5 = (char *)ht + v3;
v5[24] |= 1u;
result = *((_QWORD *)v5 + 1);
mem_busy -= result;
--ht_count;
return result;
}

original_code:
static unsigned long ht_remove(void *ptr, char *at)
{
 int idx;
 idx = (unsigned long) ptr % ht_size;
 while (ht[idx].ptr != ptr || !ht[idx].active || ht[idx].removed) {
  if (!ht[idx].active) {
   fprintf(stderr, "\n%s: free: invalid pointer %p\n",
    at, ptr);
   abort();
  }
  idx = (idx + 1) % ht_size;
 }
 check_corruption(ptr, ht[idx].size, at);
 ht[idx].removed = 1;
 mem_busy -= ht[idx].size;
 ht_count--;
 return ht[idx].size;
}

return_type: unsigned long


decompiled_code:
void __fastcall mhandle_free(__int64 a1, const char *a2)
{
__int64 v2; // rax

if ( a1 )
{
initialize();
v2 = ht_remove(a1 - 2, a2);
memset((void *)(a1 - 2), 0, v2 + 4);
free((void *)(a1 - 2));
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, const char *a2)
{
__int64 v2; // rax

if ( a1 )
{
func2();
v2 = func6(a1 - 2, a2);
memset((void *)(a1 - 2), 0, v2 + 4);
free((void *)(a1 - 2));
}
}

original_code:
void mhandle_free(void *ptr, char *at)
{
 unsigned long size;
 if (!ptr)
  return;
 initialize();
 ptr -= 2;
 size = ht_remove(ptr, at);
 bzero(ptr, size + (2 * 2));
 free(ptr);
}


decompiled_code:
char *__fastcall mhandle_strdup(void *src, const char *a2)
{
size_t v2; // rbx
size_t v3; // r13
char *v4; // rax
_BYTE *v5; // rbx
char *v6; // r14

v2 = strlen((const char *)src);
v3 = v2 + 1;
initialize();
v4 = (char *)malloc(v2 + 5);
if ( !v4 )
outofmem(a2);
v5 = v4;
v6 = v4 + 2;
memcpy(v4 + 2, src, v3);
mark_corruption(v5, v3);
ht_insert((unsigned __int64)v5, v3, (__int64)a2);
return v6;
}

canonical_decompiled_code:
char *__fastcall func11(void *src, const char *a2)
{
size_t v2; // rbx
size_t v3; // r13
char *v4; // rax
_BYTE *v5; // rbx
char *v6; // r14

v2 = strlen((const char *)src);
v3 = v2 + 1;
func2();
v4 = (char *)malloc(v2 + 5);
if ( !v4 )
func1(a2);
v5 = v4;
v6 = v4 + 2;
memcpy(v4 + 2, src, v3);
func0(v5, v3);
func4((unsigned __int64)v5, v3, (__int64)a2);
return v6;
}

original_code:
char *mhandle_strdup(const char *s, char *at)
{
 char *ptr;
 unsigned long size = strlen(s) + 1;
 initialize();
 ptr = malloc(size + (2 * 2));
 if (!ptr)
  outofmem(at);
 memcpy(ptr + 2, s, size);
 mark_corruption(ptr, size);
 ht_insert(ptr, size, at);
 return ptr + 2;
}

canonical_original_code:
char *mhandle_strdup(char *s, char *at)
{
 char *ptr;
 unsigned long size = strlen(s) + 1;
 initialize();
 ptr = malloc(size + (2 * 2));
 if (!ptr)
  outofmem(at);
 memcpy(ptr + 2, s, size);
 mark_corruption(ptr, size);
 ht_insert(ptr, size, at);
 return ptr + 2;
}

variable_types:
s
char *

variable_types:
ptr
char *


decompiled_code:
__int64 si_emu_done()
{
if ( si_emu_report_file )
fclose(si_emu_report_file);
si_opencl_repo_free_all_objects(*(_QWORD *)(si_emu + 8));
si_opencl_repo_free(*(_QWORD *)(si_emu + 8));
si_disasm_done();
si_isa_done();
mem_free(*(_QWORD *)(si_emu + 128));
m2s_timer_free(*(_QWORD *)si_emu);
return mhandle_free(si_emu, "emu.c:114");
}

canonical_decompiled_code:
__int64 func1()
{
if ( si_emu_report_file )
fclose(si_emu_report_file);
si_opencl_repo_free_all_objects(*(_QWORD *)(si_emu + 8));
si_opencl_repo_free(*(_QWORD *)(si_emu + 8));
si_disasm_done();
si_isa_done();
mem_free(*(_QWORD *)(si_emu + 128));
m2s_timer_free(*(_QWORD *)si_emu);
return mhandle_free(si_emu, "emu.c:114");
}

original_code:
void si_emu_done()
{
 if (si_emu_report_file)
  fclose(si_emu_report_file);
 si_opencl_repo_free_all_objects(si_emu->opencl_repo);
 si_opencl_repo_free(si_emu->opencl_repo);
 si_disasm_done();
 si_isa_done();
 mem_free(si_emu->global_mem);
 m2s_timer_free(si_emu->timer);
 (mhandle_free(si_emu, "emu.c" ":" "114"));
}


decompiled_code:
__int64 __fastcall si_emu_libopencl_failed(unsigned int a1)
{
return warning(
"context %d finished after failing to access OpenCL library.\n"
"\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
"\tapplication's dynamic linker. Please, make sure that this file is available\n"
"\teither in any shared library path, in the current working directory, or in\n"
"\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
"\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return warning(
"context %d finished after failing to access OpenCL library.\n"
"\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
"\tapplication's dynamic linker. Please, make sure that this file is available\n"
"\teither in any shared library path, in the current working directory, or in\n"
"\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
"\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
a1);
}

original_code:
void si_emu_libopencl_failed(int pid)
{
 warning("context %d finished after failing to access OpenCL library.\n"
  "\tMulti2Sim has detected several attempts to access 'libm2s-opencl.so' by your\n"
  "\tapplication's dynamic linker. Please, make sure that this file is available\n"
  "\teither in any shared library path, in the current working directory, or in\n"
  "\tany directory pointed by the environment variable LD_LIBRARY_PATH. See the\n"
  "\tMulti2Sim Guide for further details (www.multi2sim.org).\n",
  pid);
}

variable_types: pid int


decompiled_code:
void __fastcall __noreturn si_emu_disasm(__int64 a1)
{
__int64 v1; // r13
int i; // ebp
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // r14
int v6; // eax
__int64 v7; // rbx
char v8[248]; // [rsp+0h] [rbp-F8h] BYREF

si_disasm_init();
v1 = elf_file_create_from_path(a1);
for ( i = 0; (int)list_count(*(_QWORD *)(v1 + 56)) > i; ++i )
{
v3 = (const char **)list_get(*(_QWORD *)(v1 + 56), (unsigned int)i);
v4 = list_get(*(_QWORD *)(v1 + 32), *((unsigned int *)v3 + 4));
if ( v4 && (unsigned int)str_prefix(*v3, "__OpenCL_") )
{
if ( (unsigned int)str_suffix(*v3, "_kernel") )
{
v5 = *v3;
v6 = strlen(*v3);
str_substr(v8, 200LL, v5, 9LL, (unsigned int)(v6 - 16));
v7 = si_bin_file_create(*(_QWORD *)(v4 + 16) + *((unsigned int *)v3 + 2), *((unsigned int *)v3 + 3), v8);
printf("**\n** Disassembly for '__kernel %s'\n**\n\n", v8);
si_disasm_buffer(*(_QWORD *)(v7 + 16) + 40LL, stdout);
puts(s);
si_bin_file_free(v7);
}
}
}
elf_file_free(v1);
si_disasm_done();
_mhandle_done();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(__int64 a1)
{
__int64 v1; // r13
int i; // ebp
const char **v3; // rbx
__int64 v4; // r12
const char *v5; // r14
int v6; // eax
__int64 v7; // rbx
char v8[248]; // [rsp+0h] [rbp-F8h] BYREF

si_disasm_init();
v1 = elf_file_create_from_path(a1);
for ( i = 0; (int)list_count(*(_QWORD *)(v1 + 56)) > i; ++i )
{
v3 = (const char **)list_get(*(_QWORD *)(v1 + 56), (unsigned int)i);
v4 = list_get(*(_QWORD *)(v1 + 32), *((unsigned int *)v3 + 4));
if ( v4 && (unsigned int)str_prefix(*v3, "__OpenCL_") )
{
if ( (unsigned int)str_suffix(*v3, "_kernel") )
{
v5 = *v3;
v6 = strlen(*v3);
str_substr(v8, 200LL, v5, 9LL, (unsigned int)(v6 - 16));
v7 = si_bin_file_create(*(_QWORD *)(v4 + 16) + *((unsigned int *)v3 + 2), *((unsigned int *)v3 + 3), v8);
printf("**\n** Disassembly for '__kernel %s'\n**\n\n", v8);
si_disasm_buffer(*(_QWORD *)(v7 + 16) + 40LL, stdout);
puts(s);
si_bin_file_free(v7);
}
}
}
elf_file_free(v1);
si_disasm_done();
_mhandle_done();
exit(0);
}

original_code:
void si_emu_disasm(char *path)
{
 struct elf_file_t *elf_file;
 struct elf_symbol_t *symbol;
 struct elf_section_t *section;
 struct si_bin_file_t *amd_bin;
 char kernel_name[200];
 int i;
 si_disasm_init();
 elf_file = elf_file_create_from_path(path);
 for (i = 0; i < list_count(elf_file->symbol_table); i++)
 {
  symbol = list_get(elf_file->symbol_table, i);
  section = list_get(elf_file->section_list, symbol->section);
  if (!section)
   continue;
  if (str_prefix(symbol->name, "__OpenCL_") && str_suffix(symbol->name, "_kernel"))
  {
   str_substr(kernel_name, sizeof(kernel_name), symbol->name, 9, strlen(symbol->name) - 16);
   amd_bin = si_bin_file_create(section->buffer.ptr + symbol->value, symbol->size, kernel_name);
   printf("**\n** Disassembly for '__kernel %s'\n**\n\n", kernel_name);
   si_disasm_buffer(&amd_bin->enc_dict_entry_southern_islands->sec_text_buffer, stdout);
   printf("\n\n\n");
   si_bin_file_free(amd_bin);
  }
 }
 elf_file_free(elf_file);
 si_disasm_done();
 __mhandle_done();
 exit(0);
}

variable_types:
path
char *

variable_types: struct elf_symbol_t { char *name; unsigned int value; unsigned int size; int section; unsigned char info; unsigned char visibility; } *

variable_types: struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; } *

variable_types: struct si_bin_file_t { struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *elf_file; struct list_t *enc_dict; struct si_bin_enc_dict_entry_t { struct si_bin_enc_dict_entry_header_t { unsigned int d_machine; unsigned int d_type; unsigned int d_offset; unsigned int d_size; unsigned int d_flags; } *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct si_bin_enc_dict_entry_consts_t { float float_consts[256][4]; unsigned int int_consts[32][4]; unsigned int bool_consts[32]; } *consts; int num_gpr_used; int lds_size_used; int stack_size_used; unsigned int userElementCount; struct si_bin_enc_user_element_t { unsigned int dataClass; unsigned int apiSlot; unsigned int startUserReg; unsigned int userRegCount; } userElements[16]; struct si_bin_compute_pgm_rsrc2_t { unsigned int scrach_en; unsigned int user_sgpr; unsigned int trap_present; unsigned int tgid_x_en; unsigned int tgid_y_en; unsigned int tgid_z_en; unsigned int tg_size_en; unsigned int tidig_comp_cnt; unsigned int excp_en_msb; unsigned int lds_size; unsigned int excp_en; unsigned int; } *compute_pgm_rsrc2; } *enc_dict_entry_southern_islands; } *

user_defined_types: struct elf_file_t { char *path; struct elf_buffer_t buffer; struct Elf32_Ehdr *header; struct list_t *section_list; struct elf_section_t *string_table; struct list_t *program_header_list; struct list_t *symbol_table; }

user_defined_types: struct elf_section_t { char *name; struct Elf32_Shdr *header; struct elf_buffer_t buffer; }

user_defined_types: struct si_bin_file_t { struct elf_file_t *elf_file; struct list_t *enc_dict; struct si_bin_enc_dict_entry_t *enc_dict_entry_southern_islands; }

user_defined_types: struct si_bin_enc_dict_entry_t { struct si_bin_enc_dict_entry_header_t *header; struct elf_buffer_t pt_load_buffer; struct elf_buffer_t pt_note_buffer; struct elf_buffer_t sec_text_buffer; struct elf_buffer_t sec_data_buffer; struct elf_buffer_t sec_symtab_buffer; struct elf_buffer_t sec_strtab_buffer; struct si_bin_enc_dict_entry_consts_t *consts; int num_gpr_used; int lds_size_used; int stack_size_used; unsigned int userElementCount; struct si_bin_enc_user_element_t userElements[16]; struct si_bin_compute_pgm_rsrc2_t *compute_pgm_rsrc2; }


decompiled_code:
__int64 si_opencl_command_queue_create()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 32LL, "opencl-command-queue.c:36");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_command_queue_create");
*(_DWORD *)v0 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 4LL);
*(_DWORD *)(v0 + 4) = 1;
*(_QWORD *)(v0 + 24) = linked_list_create();
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx

v0 = mhandle_calloc(1LL, 32LL, "opencl-command-queue.c:36");
if ( !v0 )
fatal("%s: out of memory", "si_opencl_command_queue_create");
*(_DWORD *)v0 = si_opencl_repo_new_object_id(*(_QWORD *)(si_emu + 8LL), 4LL);
*(_DWORD *)(v0 + 4) = 1;
*(_QWORD *)(v0 + 24) = linked_list_create();
si_opencl_repo_add_object(*(_QWORD *)(si_emu + 8LL), v0);
return v0;
}

original_code:
struct si_opencl_command_queue_t *si_opencl_command_queue_create()
{
 struct si_opencl_command_queue_t *command_queue;
 command_queue = (mhandle_calloc(1, sizeof(struct si_opencl_command_queue_t), "opencl-command-queue.c" ":" "36"));
 if (!command_queue)
  fatal("%s: out of memory", __FUNCTION__);
 command_queue->id = si_opencl_repo_new_object_id(si_emu->opencl_repo,
  si_opencl_object_command_queue);
 command_queue->ref_count = 1;
 command_queue->command_list = linked_list_create();
 si_opencl_repo_add_object(si_emu->opencl_repo, command_queue);
 return command_queue;
}

variable_types: struct si_opencl_command_queue_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; unsigned int properties; struct linked_list_t { int count; int error_code; struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; } *head; int current_index; } *command_list; } *

user_defined_types: struct si_opencl_command_queue_t { unsigned int id; int ref_count; unsigned int device_id; unsigned int context_id; unsigned int properties; struct linked_list_t *command_list; }

user_defined_types: struct linked_list_t { int count; int error_code; struct linked_list_elem_t *head; int current_index; }


decompiled_code:
__int64 __fastcall si_opencl_command_queue_free(__int64 a1)
{
if ( (unsigned int)linked_list_count(*(_QWORD *)(a1 + 24)) )
fatal("%s: freed command queue is not empty", "si_opencl_command_queue_free");
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
linked_list_free(*(_QWORD *)(a1 + 24));
return mhandle_free(a1, "opencl-command-queue.c:62");
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( (unsigned int)linked_list_count(*(_QWORD *)(a1 + 24)) )
fatal("%s: freed command queue is not empty", "si_opencl_command_queue_free");
si_opencl_repo_remove_object(*(_QWORD *)(si_emu + 8LL), a1);
linked_list_free(*(_QWORD *)(a1 + 24));
return mhandle_free(a1, "opencl-command-queue.c:62");
}

original_code:
void si_opencl_command_queue_free(struct si_opencl_command_queue_t *command_queue)
{
 if (linked_list_count(command_queue->command_list))
  fatal("%s: freed command queue is not empty", __FUNCTION__);
 si_opencl_repo_remove_object(si_emu->opencl_repo, command_queue);
 linked_list_free(command_queue->command_list);
 (mhandle_free(command_queue, "opencl-command-queue.c" ":" "62"));
}

user_defined_types: struct linked_list_elem_t { struct linked_list_elem_t *prev; struct linked_list_elem_t *next; void *data; }


decompiled_code:
__int64 __fastcall list_grow(unsigned int *a1)
{
int v1; // er12
__int64 v2; // rbp
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // kr00_4
__int64 result; // rax

v1 = 2 * a1[2];
v2 = mhandle_calloc(v1, 8LL, "list.c:43");
if ( !v2 )
fatal("%s: out of memory", "list_grow");
v3 = a1[3];
if ( (int)*a1 > 0 )
{
v4 = 0LL;
do
{
*(_QWORD *)(v2 + 8 * v4) = *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * (int)v3);
v5 = v3 + 1;
v3 = (unsigned int)(((int)v3 + 1) >> 31);
LODWORD(v3) = __SPAIR64__(v3, v5) % (int)a1[2];
++v4;
}
while ( (int)*a1 > (int)v4 );
}
mhandle_free(*((_QWORD *)a1 + 3), "list.c:54", v3);
*((_QWORD *)a1 + 3) = v2;
a1[2] = v1;
a1[3] = 0;
result = *a1;
a1[4] = result;
return result;
}

original_code:
static void list_grow(struct list_t *list)
{
 void **nelem;
 int nsize, i, index;
 nsize = list->size * 2;
 nelem = (mhandle_calloc(nsize, sizeof(void *), "list.c" ":" "43"));
 if (!nelem)
  fatal("%s: out of memory", __FUNCTION__);
 for (i = list->head, index = 0;
  index < list->count;
  i = (i + 1) % list->size, index++)
  nelem[index] = list->elem[i];
 (mhandle_free(list->elem, "list.c" ":" "54"));
 list->elem = nelem;
 list->size = nsize;
 list->head = 0;
 list->tail = list->count;
}

canonical_original_code:
static void list_grow(struct list_t *list)
{
 void **nelem;
 int nsize; int i; int index;
 nsize = list->size * 2;
 nelem = (mhandle_calloc(nsize, sizeof(void *), "list.c" ":" "43"));
 if (!nelem)
  fatal("%s: out of memory", __FUNCTION__);
 for (i = list->head, index = 0;
  index < list->count;
  i = (i + 1) % list->size, index++)
  nelem[index] = list->elem[i];
 (mhandle_free(list->elem, "list.c" ":" "54"));
 list->elem = nelem;
 list->size = nsize;
 list->head = 0;
 list->tail = list->count;
}

variable_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *

variable_types:
nelem
void **

variable_types: nsize int

variable_types: index int


decompiled_code:
__int64 __fastcall list_create_with_size(int a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "list.c:101");
if ( !v2 )
fatal("%s: out of memory", "list_create_with_size");
if ( a1 < 4 )
v1 = 4;
*(_DWORD *)(v2 + 8) = v1;
v3 = mhandle_calloc(v1, 8LL, "list.c:107");
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
fatal("%s: out of memory", "list_create_with_size");
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // rax

v1 = a1;
v2 = mhandle_calloc(1LL, 32LL, "list.c:101");
if ( !v2 )
fatal("%s: out of memory", "list_create_with_size");
if ( a1 < 4 )
v1 = 4;
*(_DWORD *)(v2 + 8) = v1;
v3 = mhandle_calloc(v1, 8LL, "list.c:107");
*(_QWORD *)(v2 + 24) = v3;
if ( !v3 )
fatal("%s: out of memory", "list_create_with_size");
return v2;
}

original_code:
struct list_t *list_create_with_size(int size)
{
 struct list_t *list;
 list = (mhandle_calloc(1, sizeof(struct list_t), "list.c" ":" "101"));
 if (!list)
  fatal("%s: out of memory", __FUNCTION__);
 list->size = size < 4 ? 4 : size;
 list->elem = (mhandle_calloc(list->size, sizeof(void *), "list.c" ":" "107"));
 if (!list->elem)
  fatal("%s: out of memory", __FUNCTION__);
 return list;
}

variable_types: size int

return_type: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *


decompiled_code:
__int64 list_create()
{
return list_create_with_size(8);
}

canonical_decompiled_code:
__int64 func3()
{
return func2(8);
}

original_code:
struct list_t *list_create(void)
{
 return list_create_with_size(8);
}

canonical_original_code:
struct list_t *list_create()
{
 return list_create_with_size(8);
}

user_defined_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; }


decompiled_code:
__int64 __fastcall list_free(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx

mhandle_free(*(_QWORD *)(a1 + 24), "list.c:125", a3);
return mhandle_free(a1, "list.c:126", v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v3; // rdx

mhandle_free(*(_QWORD *)(a1 + 24), "list.c:125", a3);
return mhandle_free(a1, "list.c:126", v3);
}

original_code:
void list_free(struct list_t *list)
{
 (mhandle_free(list->elem, "list.c" ":" "125"));
 (mhandle_free(list, "list.c" ":" "126"));
}


decompiled_code:
__int64 __fastcall list_count(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1)
{
return *a1;
}

original_code:
int list_count(struct list_t *list)
{
 return list->count;
}


original_code:
void list_add(struct list_t *list, void *elem)
{
 if (list->count == list->size)
  list_grow(list);
 list->elem[list->tail] = elem;
 list->tail = (list->tail + 1) % list->size;
 list->count++;
 list->error_code = LIST_ERR_OK;
}

variable_types:
elem
void *


original_code:
void *list_get(struct list_t *list, int index)
{
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return ((void *)0);
 }
 index = (index + list->head) % list->size;
 list->error_code = LIST_ERR_OK;
 return list->elem[index];
}

return_type: void *


decompiled_code:
__int64 __fastcall list_set(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

result = (unsigned int)a2;
if ( a2 < 0 || *(_DWORD *)a1 <= a2 )
{
*(_DWORD *)(a1 + 4) = 1;
}
else
{
result = *(_QWORD *)(a1 + 24);
*(_QWORD *)(result + 8LL * ((*(_DWORD *)(a1 + 12) + a2) % *(_DWORD *)(a1 + 8))) = a3;
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

original_code:
void list_set(struct list_t *list, int index, void *elem)
{
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return;
 }
 index = (index + list->head) % list->size;
 list->elem[index] = elem;
 list->error_code = LIST_ERR_OK;
}


original_code:
void list_insert(struct list_t *list, int index, void *elem)
{
 int shiftcount;
 int pos;
 int i;
 if (index < 0 || index > list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return;
 }
 if (list->count == list->size)
  list_grow(list);
 if (index > list->count / 2)
 {
  shiftcount = list->count - index;
  for (i = 0, pos = list->tail;
    i < shiftcount;
    i++, pos = (((pos - 1) + list->size) % list->size))
   list->elem[pos] = list->elem[(((pos - 1) + list->size) % list->size)];
  list->tail = (list->tail + 1) % list->size;
 }
 else
 {
  for (i = 0, pos = list->head;
    i < index;
    i++, pos = (pos + 1) % list->size)
   list->elem[(((pos - 1) + list->size) % list->size)] = list->elem[pos];
  list->head = (((list->head - 1) + list->size) % list->size);
 }
 list->elem[(list->head + index) % list->size] = elem;
 list->count++;
 list->error_code = LIST_ERR_OK;
}

variable_types: shiftcount int

variable_types: pos int

variable_types: i int


original_code:
int list_index_of(struct list_t *list, void *elem)
{
 int pos;
 int i;
 list->error_code = LIST_ERR_OK;
 for (i = 0, pos = list->head;
  i < list->count;
  i++, pos = (pos + 1) % list->size)
 {
  if (list->elem[pos] == elem)
   return i;
 }
 list->error_code = LIST_ERR_NOT_FOUND;
 return -1;
}


original_code:
void *list_remove_at(struct list_t *list, int index)
{
 int shiftcount;
 int pos;
 int i;
 void *elem;
 if (index < 0 || index >= list->count)
 {
  list->error_code = LIST_ERR_BOUNDS;
  return ((void *)0);
 }
 elem = list->elem[(list->head + index) % list->size];
 if (index > list->count / 2)
 {
  shiftcount = list->count - index - 1;
  for (i = 0, pos = (list->head + index) % list->size;
    i < shiftcount;
    i++, pos = (pos + 1) % list->size)
   list->elem[pos] = list->elem[(pos + 1) % list->size];
  list->elem[pos] = ((void *)0);
  list->tail = (((list->tail - 1) + list->size) % list->size);
 }
 else
 {
  for (i = 0, pos = (list->head + index) % list->size;
    i < index;
    i++, pos = (((pos - 1) + list->size) % list->size))
   list->elem[pos] = list->elem[(((pos - 1) + list->size) % list->size)];
  list->elem[list->head] = ((void *)0);
  list->head = (list->head + 1) % list->size;
 }
 list->count--;
 list->error_code = LIST_ERR_OK;
 return elem;
}


decompiled_code:
__int64 __fastcall list_remove(int *a1, __int64 a2)
{
int v2; // esi
__int64 result; // rax

v2 = list_index_of((__int64)a1, a2);
result = 0LL;
if ( !a1[1] )
result = list_remove_at(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, __int64 a2)
{
int v2; // esi
__int64 result; // rax

v2 = func10((__int64)a1, a2);
result = 0LL;
if ( !a1[1] )
result = func11(a1, v2);
return result;
}

original_code:
void *list_remove(struct list_t *list, void *elem)
{
 int index;
 index = list_index_of(list, elem);
 if (list->error_code)
  return ((void *)0);
 return list_remove_at(list, index);
}


decompiled_code:
__int64 __fastcall list_sort(_DWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax

if ( *a1 )
result = sort((__int64)a1, 0, *a1 - 1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(_DWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64))
{
__int64 result; // rax

if ( *a1 )
result = func0((__int64)a1, 0, *a1 - 1, a2);
return result;
}

original_code:
void list_sort(struct list_t *list, int (*comp)(const void *, const void *))
{
 if (list->count)
  sort(list, 0, list->count - 1, comp);
}

canonical_original_code:
void list_sort(struct list_t *list, int (*comp)(void *, void *))
{
 if (list->count)
  sort(list, 0, list->count - 1, comp);
}

variable_types:
comp
int (*)(void *, void *)


decompiled_code:
__int64 __fastcall list_push(__int64 a1, __int64 a2)
{
return list_add(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2)
{
return func6(a1, a2);
}

original_code:
void list_push(struct list_t *list, void *elem)
{
 list_add(list, elem);
}


decompiled_code:
__int64 __fastcall list_pop(int *a1)
{
if ( *a1 )
return list_remove_at(a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(int *a1)
{
if ( *a1 )
return func11(a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_pop(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_remove_at(list, list->count - 1);
}


decompiled_code:
__int64 __fastcall list_top(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func17(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_top(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, list->count - 1);
}


decompiled_code:
__int64 __fastcall list_bottom(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func18(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_bottom(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, 0);
}


decompiled_code:
__int64 __fastcall list_enqueue(__int64 a1, __int64 a2)
{
return list_add(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, __int64 a2)
{
return func6(a1, a2);
}

original_code:
void list_enqueue(struct list_t *list, void *elem)
{
 list_add(list, elem);
}


decompiled_code:
__int64 __fastcall list_dequeue(int *a1)
{
if ( *a1 )
return list_remove_at(a1, 0);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(int *a1)
{
if ( *a1 )
return func11(a1, 0);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_dequeue(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_remove_at(list, 0);
}


decompiled_code:
__int64 __fastcall list_head(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func21(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, 0);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_head(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, 0);
}


decompiled_code:
__int64 __fastcall list_tail(_DWORD *a1)
{
if ( *a1 )
return list_get((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func22(_DWORD *a1)
{
if ( *a1 )
return func7((__int64)a1, *a1 - 1);
a1[1] = 3;
return 0LL;
}

original_code:
void *list_tail(struct list_t *list)
{
 if (!list->count)
 {
  list->error_code = LIST_ERR_EMPTY;
  return ((void *)0);
 }
 return list_get(list, list->count - 1);
}


sort

original_code:
static void sort(struct list_t *list, int lo, int hi,
 int (*comp)(const void *, const void *))
{
 void *ptr, *tmp;
 int i = lo, j = hi;
 ptr = list->elem[((hi) + list->head) % list->size];
 do
 {
  while (comp(list->elem[((i) + list->head) % list->size], ptr) < 0)
   i++;
  while (comp(list->elem[((j) + list->head) % list->size], ptr) > 0)
   j--;
  if (i <= j)
  {
   tmp = list->elem[((i) + list->head) % list->size];
   list->elem[((i) + list->head) % list->size] = list->elem[((j) + list->head) % list->size];
   list->elem[((j) + list->head) % list->size] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(list, lo, j, comp);
 if (i < hi)
  sort(list, i, hi, comp);
}

canonical_original_code:
static void sort(struct list_t *list, int lo, int hi, int (*comp)(void *, void *))
{
 void *ptr; void *tmp;
 int i = lo; int j = hi;
 ptr = list->elem[((hi) + list->head) % list->size];
 do
 {
  while (comp(list->elem[((i) + list->head) % list->size], ptr) < 0)
   i++;
  while (comp(list->elem[((j) + list->head) % list->size], ptr) > 0)
   j--;
  if (i <= j)
  {
   tmp = list->elem[((i) + list->head) % list->size];
   list->elem[((i) + list->head) % list->size] = list->elem[((j) + list->head) % list->size];
   list->elem[((j) + list->head) % list->size] = tmp;
   i++, j--;
  }
 } while (i <= j);
 if (lo < j)
  sort(list, lo, j, comp);
 if (i < hi)
  sort(list, i, hi, comp);
}

variable_types: lo int

variable_types: hi int

variable_types:
ptr
void *

variable_types:
tmp
void *

variable_types: j int


decompiled_code:
__int64 __fastcall amd_opengl_shader_set_shader_kind(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // eax

v2 = *(_QWORD *)(a1 + 8);
v3 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 24LL) + 36LL);
switch ( v3 )
{
case 1:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 1 )
{
*(_DWORD *)a1 = 1;
return 1LL;
}
LABEL_7:
fatal("Unknown shader kind!\n", a2, v2);
return 1LL;
case 2:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 2 )
{
*(_DWORD *)a1 = 0;
return 1LL;
}
goto LABEL_7;
case 3:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 3 )
{
*(_DWORD *)a1 = 2;
return 1LL;
}
goto LABEL_7;
case 5:
if ( *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) == 5 )
{
*(_DWORD *)a1 = 4;
return 1LL;
}
goto LABEL_7;
}
if ( v3 != 6 || *(_DWORD *)(*(_QWORD *)(v2 + 24) + 36LL) != 6 )
goto LABEL_7;
*(_DWORD *)a1 = 3;
return 1LL;
}

original_code:
static int amd_opengl_shader_set_shader_kind(struct evg_opengl_shader_t *opengl_shader)
{
 struct elf_file_t *internal_elf_file;
 struct elf_file_t *external_elf_file;
 internal_elf_file = opengl_shader->internal_elf_file;
 external_elf_file = opengl_shader->external_elf_file;
 if (internal_elf_file->header->e_flags == 0x1 && external_elf_file->header->e_flags == 0x1)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_FRAGMENT;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x2 && external_elf_file->header->e_flags == 0x2)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_VERTEX;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x3 && external_elf_file->header->e_flags == 0x3)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_GEOMETRY;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x5 && external_elf_file->header->e_flags == 0x5)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_CONTROL;
  return 1;
 }
 else if (internal_elf_file->header->e_flags == 0x6 && external_elf_file->header->e_flags == 0x6)
 {
  opengl_shader->shader_kind = EVG_OPENGL_SHADER_EVALUATION;
  return 1;
 }
 else
 {
  fatal("Unknown shader kind!\n");
 }
 return 1;
}

variable_types: struct evg_opengl_shader_t { enum evg_opengl_shader_kind_t { EVG_OPENGL_SHADER_VERTEX=0, EVG_OPENGL_SHADER_FRAGMENT=1, EVG_OPENGL_SHADER_GEOMETRY=2, EVG_OPENGL_SHADER_EVALUATION=3, EVG_OPENGL_SHADER_CONTROL=4 } shader_kind; struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *external_elf_file; struct elf_file_t *internal_elf_file; struct elf_buffer_t isa_buffer; } *

user_defined_types: struct evg_opengl_shader_t { enum evg_opengl_shader_kind_t shader_kind; struct elf_file_t *external_elf_file; struct elf_file_t *internal_elf_file; struct elf_buffer_t isa_buffer; }


decompiled_code:
__int64 __fastcall elf_file_list_create(void *s1, __int64 a2)
{
__int64 v2; // r14
char *v3; // rbx
_DWORD *v4; // rbp
int s2[11]; // [rsp+Ch] [rbp-2Ch] BYREF

s2[0] = 1179403647;
v2 = list_create();
if ( a2 != 4 )
{
v3 = (char *)s1;
do
{
if ( !memcmp(v3, s2, 4uLL) )
{
v4 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opengl-bin-file.c:66");
if ( !v4 )
fatal("%s: out of memory", "elf_file_list_create");
*v4 = (_DWORD)v3 - (_DWORD)s1;
list_add(v2, v4);
}
++v3;
}
while ( (char *)s1 + a2 - 4 != v3 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *s1, __int64 a2)
{
__int64 v2; // r14
char *v3; // rbx
_DWORD *v4; // rbp
int s2[11]; // [rsp+Ch] [rbp-2Ch] BYREF

s2[0] = 1179403647;
v2 = list_create();
if ( a2 != 4 )
{
v3 = (char *)s1;
do
{
if ( !memcmp(v3, s2, 4uLL) )
{
v4 = (_DWORD *)mhandle_calloc(1LL, 4LL, "opengl-bin-file.c:66");
if ( !v4 )
fatal("%s: out of memory", "elf_file_list_create");
*v4 = (_DWORD)v3 - (_DWORD)s1;
list_add(v2, v4);
}
++v3;
}
while ( (char *)s1 + a2 - 4 != v3 );
}
return v2;
}

original_code:
static struct list_t *elf_file_list_create(void *ptr_buffer, size_t buf_size)
{
 const char ELF_magic[4] = { 0x7F, 0x45, 0x4C, 0x46};
 struct list_t *elf_file_list;
 void *ptr_copy;
 int *offset;
 int i;
 elf_file_list = list_create();
 ptr_copy = ptr_buffer;
 for (i = 0; i < buf_size - sizeof(ELF_magic); i++)
 {
  if (memcmp(ptr_copy, ELF_magic, sizeof(ELF_magic)) == 0)
  {
   offset = (mhandle_calloc(1, sizeof(int), "opengl-bin-file.c" ":" "66"));
   if (!offset)
    fatal("%s: out of memory", __FUNCTION__);
   *offset = (int)(ptr_copy - ptr_buffer);
   list_add(elf_file_list, offset);
  }
  ptr_copy++;
 }
 return elf_file_list;
}

canonical_original_code:
static struct list_t *elf_file_list_create(void *ptr_buffer, unsigned long buf_size)
{
 char ELF_magic[4] = { 0x7F, 0x45, 0x4C, 0x46};
 struct list_t *elf_file_list;
 void *ptr_copy;
 int *offset;
 int i;
 elf_file_list = list_create();
 ptr_copy = ptr_buffer;
 for (i = 0; i < buf_size - sizeof(ELF_magic); i++)
 {
  if (memcmp(ptr_copy, ELF_magic, sizeof(ELF_magic)) == 0)
  {
   offset = (mhandle_calloc(1, sizeof(int), "opengl-bin-file.c" ":" "66"));
   if (!offset)
    fatal("%s: out of memory", __FUNCTION__);
   *offset = (int)(ptr_copy - ptr_buffer);
   list_add(elf_file_list, offset);
  }
  ptr_copy++;
 }
 return elf_file_list;
}

variable_types:
offset
int *


decompiled_code:
__int64 __fastcall external_elf_file_create(__int64 a1, int a2, __int64 a3, unsigned int a4, __int64 a5)
{
int *v6; // rax

v6 = (int *)list_get(a3, a4);
return elf_file_create_from_buffer(a1 + *v6, (unsigned int)(a2 - *v6), a5);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3, unsigned int a4, __int64 a5)
{
int *v6; // rax

v6 = (int *)list_get(a3, a4);
return elf_file_create_from_buffer(a1 + *v6, (unsigned int)(a2 - *v6), a5);
}

original_code:
static struct elf_file_t *external_elf_file_create(void *ptr_buffer, int buf_size, struct list_t *elf_offset_list, int elf_file_index, char *name)
{
 struct elf_file_t *external_elf_file;
 int *external_elf_offset;
 void *external_elf_base;
 int external_elf_size;
 external_elf_offset = list_get(elf_offset_list,elf_file_index);
 external_elf_base = ptr_buffer + *external_elf_offset;
 external_elf_size = buf_size - *external_elf_offset;
 external_elf_file = elf_file_create_from_buffer(external_elf_base, external_elf_size, name);
 return external_elf_file;
}

variable_types:
name
char *

variable_types: struct elf_file_t { char *path; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; } *header; struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *section_list; struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t buffer; } *string_table; struct list_t *program_header_list; struct list_t *symbol_table; } *


decompiled_code:
__int64 internal_elf_file_free()
{
return elf_file_free();
}

canonical_decompiled_code:
__int64 func6()
{
return elf_file_free();
}

original_code:
static void internal_elf_file_free(struct elf_file_t *internal_elf_file)
{
 elf_file_free(internal_elf_file);
}

user_defined_types: struct elf_buffer_t { void *ptr; int size; int pos; }

user_defined_types: struct Elf32_Ehdr { unsigned char e_ident[-1]; unsigned short e_type; unsigned short e_machine; unsigned int e_version; unsigned int e_entry; unsigned int e_phoff; unsigned int e_shoff; unsigned int e_flags; unsigned short e_ehsize; unsigned short e_phentsize; unsigned short e_phnum; unsigned short e_shentsize; unsigned short e_shnum; unsigned short e_shstrndx; }

user_defined_types: struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; }


decompiled_code:
__int64 __fastcall amd_opengl_shader_free(__int64 a1)
{
external_elf_file_free(*(_QWORD *)(a1 + 8));
internal_elf_file_free(*(_QWORD *)(a1 + 16));
return mhandle_free(a1, "opengl-bin-file.c:365");
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
func5(*(_QWORD *)(a1 + 8));
func6(*(_QWORD *)(a1 + 16));
return mhandle_free(a1, "opengl-bin-file.c:365");
}

original_code:
static void amd_opengl_shader_free(struct evg_opengl_shader_t *opengl_shader)
{
 external_elf_file_free(opengl_shader->external_elf_file);
 internal_elf_file_free(opengl_shader->internal_elf_file);
 (mhandle_free(opengl_shader, "opengl-bin-file.c" ":" "365"));
}

user_defined_types: enum evg_opengl_shader_kind_t { EVG_OPENGL_SHADER_VERTEX=0, EVG_OPENGL_SHADER_FRAGMENT=1, EVG_OPENGL_SHADER_GEOMETRY=2, EVG_OPENGL_SHADER_EVALUATION=3, EVG_OPENGL_SHADER_CONTROL=4 }


decompiled_code:
__int64 __fastcall is_external_elf(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int i; // ebp
bool v4; // zf
_BOOL4 v5; // ebx

v2 = elf_file_create_from_buffer(a1, a2, 0LL);
if ( (unsigned int)list_count(*(_QWORD *)(v2 + 32)) == 5 )
{
for ( i = 0; (int)list_count(*(_QWORD *)(v2 + 32)) > i; ++i )
{
v4 = strcmp(*(const char **)list_get(*(_QWORD *)(v2 + 32), (unsigned int)i), "binary") == 0;
v5 = !v4;
if ( v4 )
{
elf_file_free(v2);
return v5;
}
}
}
elf_file_free(v2);
return -1;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int i; // ebp
bool v4; // zf
_BOOL4 v5; // ebx

v2 = elf_file_create_from_buffer(a1, a2, 0LL);
if ( (unsigned int)list_count(*(_QWORD *)(v2 + 32)) == 5 )
{
for ( i = 0; (int)list_count(*(_QWORD *)(v2 + 32)) > i; ++i )
{
v4 = strcmp(*(const char **)list_get(*(_QWORD *)(v2 + 32), (unsigned int)i), "binary") == 0;
v5 = !v4;
if ( v4 )
{
elf_file_free(v2);
return v5;
}
}
}
elf_file_free(v2);
return -1;
}

original_code:
static int is_external_elf(void *ptr_buffer, int buf_size)
{
 struct elf_file_t *elf_file;
 int i;
 struct elf_section_t *elf_section;
 elf_file = elf_file_create_from_buffer(ptr_buffer, buf_size, ((void *)0));
 if (list_count(elf_file->section_list) != 5)
 {
  elf_file_free(elf_file);
  return -1;
 }
 else
 {
  for (i = 0; i < list_count(elf_file->section_list); i++)
  {
   elf_section = list_get(elf_file->section_list, i);
   if(!strcmp(elf_section->name,"binary"))
   {
    elf_file_free(elf_file);
    return 0;
   }
  }
  elf_file_free(elf_file);
  return -1;
 }
 return -1;
}

variable_types: struct elf_section_t { char *name; struct Elf32_Shdr { unsigned int sh_name; unsigned int sh_type; unsigned int sh_flags; unsigned int sh_addr; unsigned int sh_offset; unsigned int sh_size; unsigned int sh_link; unsigned int sh_info; unsigned int sh_addralign; unsigned int sh_entsize; } *header; struct elf_buffer_t { void *ptr; int size; int pos; } buffer; } *


decompiled_code:
__int64 __fastcall external_elf_file_list_create(void *a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int i; // ebx
int *v4; // rax
__int64 v5; // rax

v2 = elf_file_list_create(a1, a2);
for ( i = 0; (int)list_count(v2) > (int)i; ++i )
{
v4 = (int *)list_get(v2, i);
if ( (unsigned int)is_external_elf((__int64)a1 + *v4, (unsigned int)(a2 - *v4)) )
{
v5 = list_remove_at(v2, i);
mhandle_free(v5, "opengl-bin-file.c:138");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(void *a1, __int64 a2)
{
__int64 v2; // rbp
unsigned int i; // ebx
int *v4; // rax
__int64 v5; // rax

v2 = func2(a1, a2);
for ( i = 0; (int)list_count(v2) > (int)i; ++i )
{
v4 = (int *)list_get(v2, i);
if ( (unsigned int)func8((__int64)a1 + *v4, (unsigned int)(a2 - *v4)) )
{
v5 = list_remove_at(v2, i);
mhandle_free(v5, "opengl-bin-file.c:138");
}
}
return v2;
}

original_code:
static struct list_t *external_elf_file_list_create(void *ptr_buffer, size_t buf_size)
{
 struct list_t *elf_file_list_external;
 int i;
 int elf_file_size;
 int *offset;
 elf_file_list_external = elf_file_list_create(ptr_buffer, buf_size);
 for (i = 0; i < list_count(elf_file_list_external); i++)
 {
  offset = list_get(elf_file_list_external, i);
  elf_file_size = buf_size - *offset;
  if (is_external_elf(ptr_buffer + *offset, elf_file_size) != 0)
   (mhandle_free(list_remove_at(elf_file_list_external, i), "opengl-bin-file.c" ":" "138"));
 }
 return elf_file_list_external;
}

canonical_original_code:
static struct list_t *external_elf_file_list_create(void *ptr_buffer, unsigned long buf_size)
{
 struct list_t *elf_file_list_external;
 int i;
 int elf_file_size;
 int *offset;
 elf_file_list_external = elf_file_list_create(ptr_buffer, buf_size);
 for (i = 0; i < list_count(elf_file_list_external); i++)
 {
  offset = list_get(elf_file_list_external, i);
  elf_file_size = buf_size - *offset;
  if (is_external_elf(ptr_buffer + *offset, elf_file_size) != 0)
   (mhandle_free(list_remove_at(elf_file_list_external, i), "opengl-bin-file.c" ":" "138"));
 }
 return elf_file_list_external;
}

variable_types: struct list_t { int count; int error_code; int size; int head; int tail; void **elem; } *