#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *__xmalloc(scalar_t__, char *);
void *dlsym(void *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ strlen(char const *);
void *opencl_x86_kernel_get_func_info(void *dlhandle, const char *func_name,
                                      size_t **metadata) {
  void *addr;
  char *full_name;
  char *meta_name;
  full_name = (__xmalloc(
      (strlen(func_name) + 100),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/"
      "HSA_Develop/runtime/opencl/x86-kernel.c"
      ":"
      "158"));
  meta_name = (__xmalloc(
      (strlen(func_name) + 100),
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/"
      "HSA_Develop/runtime/opencl/x86-kernel.c"
      ":"
      "159"));
  sprintf(full_name, "__OpenCL_%s_kernel", func_name);
  sprintf(meta_name, "__OpenCL_%s_metadata", func_name);
  *metadata = (size_t *)dlsym(dlhandle, meta_name);
  addr = dlsym(dlhandle, full_name);
  free(full_name);
  free(meta_name);
  return addr;
}


x86 assembly (clang, -O0):
<opencl_x86_kernel_get_func_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x64,%rdi
lea    0xe85(%rip),%rsi
call   1050 <__xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x64,%rdi
lea    0xf13(%rip),%rsi
call   1050 <__xmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xfa9(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xfa8(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <dlsym@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <dlsym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opencl_x86_kernel_get_func_info>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x64(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <__xmalloc@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x64(%rax),%rdi
lea    0xf1e(%rip),%rsi
call   1050 <__xmalloc@plt>
mov    %rax,%r13
lea    0xfbd(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
lea    0xfbe(%rip),%rsi
mov    %r13,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <dlsym@plt>
mov    %rax,(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <dlsym@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/runtime/opencl/x86-kernel.c:158\00"
@.str.1 = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/runtime/opencl/x86-kernel.c:159\00"
@.str.2 = [19 x i8] c"__OpenCL_%s_kernel\00"
@.str.3 = [21 x i8] c"__OpenCL_%s_metadata\00"
define i8* @opencl_x86_kernel_get_func_info(i8* %0, i8* %1, i64** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64** %2, i64*** %6
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 100
%13 = call i8* @__xmalloc(i64 %12, i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 100
%17 = call i8* @__xmalloc(i64 %16, i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %9
%18 = load i8*, i8** %8
%19 = load i8*, i8** %5
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %9
%22 = load i8*, i8** %5
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %4
%25 = load i8*, i8** %9
%26 = call i8* @dlsym(i8* %24, i8* %25)
%27 = bitcast i8* %26 to i64*
%28 = load i64**, i64*** %6
store i64* %27, i64** %28
%29 = load i8*, i8** %4
%30 = load i8*, i8** %8
%31 = call i8* @dlsym(i8* %29, i8* %30)
store i8* %31, i8** %7
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %9
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %7
ret i8* %36
}

LLVM IR (-O2):
@.str = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/runtime/opencl/x86-kernel.c:158\00"
@.str.1 = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MrWhoami/lacs_implementation/refs/heads/HSA_Develop/runtime/opencl/x86-kernel.c:159\00"
@.str.2 = [19 x i8] c"__OpenCL_%s_kernel\00"
@.str.3 = [21 x i8] c"__OpenCL_%s_metadata\00"
define i8* @opencl_x86_kernel_get_func_info(i8* %0, i8* %1, i64** nocapture writeonly %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add nsw i64 %4, 100
%6 = tail call i8* @__xmalloc(i64 %5, i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add nsw i64 %7, 100
%9 = tail call i8* @__xmalloc(i64 %8, i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%12 = tail call i8* @dlsym(i8* %0, i8* %9)
%13 = bitcast i64** %2 to i8**
store i8* %12, i8** %13
%14 = tail call i8* @dlsym(i8* %0, i8* %6)
%15 = tail call i32 @free(i8* %6)
%16 = tail call i32 @free(i8* %9)
ret i8* %14
}