#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 */
typedef char cl_program;
typedef int /*<<< orphan*/ cl_kernel;
typedef int /*<<< orphan*/ cl_int;

/* Variables and functions */
int /*<<< orphan*/ CL_KERNEL_FUNCTION_NAME;
int /*<<< orphan*/ CL_KERNEL_PROGRAM;
int /*<<< orphan*/ check_cl_error(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ clCreateKernel(char, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clGetKernelInfo(int /*<<< orphan*/, int /*<<< orphan*/,
                                   size_t, char *, size_t *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
cl_kernel kernelDuplicate(cl_kernel kernel) {
  cl_int cl_err;
  cl_kernel new_kernel;
  cl_program program;
  char *kernel_name;
  size_t name_length;
  cl_err = clGetKernelInfo(kernel, CL_KERNEL_PROGRAM, sizeof(cl_program),
                           &program, NULL);
  check_cl_error(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/"
      "refs/heads/master/src/detector/bufferOverflowDetect.c",
      339, cl_err);
  cl_err =
      clGetKernelInfo(kernel, CL_KERNEL_FUNCTION_NAME, 0, NULL, &name_length);
  check_cl_error(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/"
      "refs/heads/master/src/detector/bufferOverflowDetect.c",
      342, cl_err);
  kernel_name = (char *)malloc(sizeof(char) * name_length);
  cl_err = clGetKernelInfo(kernel, CL_KERNEL_FUNCTION_NAME, name_length,
                           kernel_name, NULL);
  check_cl_error(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/"
      "refs/heads/master/src/detector/bufferOverflowDetect.c",
      346, cl_err);
  new_kernel = clCreateKernel(program, kernel_name, &cl_err);
  check_cl_error(
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/"
      "refs/heads/master/src/detector/bufferOverflowDetect.c",
      349, cl_err);
  if (kernel_name != NULL)
    free(kernel_name);
  return new_kernel;
}


x86 assembly (clang, -O0):
<kernelDuplicate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
lea    -0xd(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetKernelInfo@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edx
lea    0xe79(%rip),%rdi
mov    $0x153,%esi
call   1050 <check_cl_error@plt>
mov    -0x4(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1040 <clGetKernelInfo@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edx
lea    0xe46(%rip),%rdi
mov    $0x156,%esi
call   1050 <check_cl_error@plt>
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetKernelInfo@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edx
lea    0xdfe(%rip),%rdi
mov    $0x15a,%esi
call   1050 <check_cl_error@plt>
mov    -0xd(%rbp),%al
mov    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdx
movsbl %al,%edi
call   1070 <clCreateKernel@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edx
lea    0xdd4(%rip),%rdi
mov    $0x15d,%esi
call   1050 <check_cl_error@plt>
cmpq   $0x0,-0x18(%rbp)
je     124a <kernelDuplicate+0xfa>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernelDuplicate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xb(%rsp),%rcx
mov    $0x1,%edx
xor    %r8d,%r8d
call   1040 <clGetKernelInfo@plt>
lea    0xe82(%rip),%r14
mov    %r14,%rdi
mov    $0x153,%esi
mov    %eax,%edx
call   1050 <check_cl_error@plt>
mov    0x2e5c(%rip),%r15
mov    (%r15),%esi
lea    0x10(%rsp),%r8
mov    %ebp,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <clGetKernelInfo@plt>
mov    %r14,%rdi
mov    $0x156,%esi
mov    %eax,%edx
call   1050 <check_cl_error@plt>
mov    0x10(%rsp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%esi
mov    0x10(%rsp),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
xor    %r8d,%r8d
call   1040 <clGetKernelInfo@plt>
mov    %eax,0xc(%rsp)
mov    %r14,%rdi
mov    $0x15a,%esi
mov    %eax,%edx
call   1050 <check_cl_error@plt>
movsbl 0xb(%rsp),%edi
lea    0xc(%rsp),%rdx
mov    %rbx,%rsi
call   1070 <clCreateKernel@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    $0x15d,%esi
call   1050 <check_cl_error@plt>
test   %rbx,%rbx
je     121c <kernelDuplicate+0xcc>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_KERNEL_PROGRAM = global i32 0
@.str = [186 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/refs/heads/master/src/detector/bufferOverflowDetect.c\00"
@CL_KERNEL_FUNCTION_NAME = global i32 0
define i32 @kernelDuplicate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @CL_KERNEL_PROGRAM
%10 = call i32 @clGetKernelInfo(i32 %8, i32 %9, i64 1, i8* %5, i64* null)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 339, i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* @CL_KERNEL_FUNCTION_NAME
%15 = call i32 @clGetKernelInfo(i32 %13, i32 %14, i64 0, i8* null, i64* %7)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 342, i32 %16)
%18 = load i64, i64* %7
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %6
%23 = load i32, i32* %2
%24 = load i32, i32* @CL_KERNEL_FUNCTION_NAME
%25 = load i64, i64* %7
%26 = load i8*, i8** %6
%27 = call i32 @clGetKernelInfo(i32 %23, i32 %24, i64 %25, i8* %26, i64* null)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 346, i32 %28)
%30 = load i8, i8* %5
%31 = load i8*, i8** %6
%32 = call i32 @clCreateKernel(i8 signext %30, i8* %31, i32* %3)
store i32 %32, i32* %4
%33 = load i32, i32* %3
%34 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 349, i32 %33)
%35 = load i8*, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %1
%38 = load i8*, i8** %6
%39 = call i32 @free(i8* %38)
br label %40
40: ; preds = %37, %1
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@CL_KERNEL_PROGRAM = global i32 0
@.str = [186 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/GPUOpen-ProfessionalCompute-Tools/clARMOR/refs/heads/master/src/detector/bufferOverflowDetect.c\00"
@CL_KERNEL_FUNCTION_NAME = global i32 0
define i32 @kernelDuplicate(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i64
%5 = bitcast i32* %2 to i8*
%6 = bitcast i64* %4 to i8*
%7 = load i32, i32* @CL_KERNEL_PROGRAM
%8 = call i32 @clGetKernelInfo(i32 %0, i32 %7, i64 1, i8* %3, i64* null)
%9 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 339, i32 %8)
%10 = load i32, i32* @CL_KERNEL_FUNCTION_NAME
%11 = call i32 @clGetKernelInfo(i32 %0, i32 %10, i64 0, i8* null, i64* %4)
%12 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 342, i32 %11)
%13 = load i64, i64* %4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = load i32, i32* @CL_KERNEL_FUNCTION_NAME
%18 = load i64, i64* %4
%19 = call i32 @clGetKernelInfo(i32 %0, i32 %17, i64 %18, i8* %16, i64* null)
store i32 %19, i32* %2
%20 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 346, i32 %19)
%21 = load i8, i8* %3
%22 = call i32 @clCreateKernel(i8 signext %21, i8* %16, i32* %2)
%23 = load i32, i32* %2
%24 = call i32 @check_cl_error(i8* getelementptr inbounds ([186 x i8], [186 x i8]* @.str, i64 0, i64 0), i32 349, i32 %23)
%25 = icmp eq i64 %15, 0
br i1 %25, label %28, label %26
26: ; preds = %1
%27 = call i32 @free(i8* %16)
br label %28
28: ; preds = %26, %1
ret i32 %22
}