#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 int /*<<< orphan*/ cl_program;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_device_id;
typedef int /*<<< orphan*/ cl_context;

/* Variables and functions */
scalar_t__ CL_SUCCESS;
scalar_t__ clBuildProgram(int /*<<< orphan*/, int, int /*<<< orphan*/ *, char *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ clCreateProgramWithSource(int /*<<< orphan*/, int,
                                             char const **, size_t *,
                                             scalar_t__ *);
int /*<<< orphan*/ clu_CheckErrorInternal(scalar_t__, char *, char *, int);
char *clu_LoadProgSource(char *, size_t *);
int /*<<< orphan*/ clu_PrintBuildLog(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
size_t strlen(char *);
cl_program clu_MakeProgram(cl_context context, cl_device_id device,
                           char *source_dir, char *source_file,
                           char *build_option) {
  cl_program program;
  cl_int err_code;
  char *source_path = source_file;
  char *build_opts = build_option;
  size_t sdir_len = strlen(source_dir);
  if (sdir_len > 0) {
    if (source_dir[sdir_len - 1] == '/') {
      source_path = (char *)malloc(sdir_len + strlen(source_file) + 1);
      sprintf(source_path, "%s%s", source_dir, source_file);
    } else {
      source_path = (char *)malloc(sdir_len + strlen(source_file) + 2);
      sprintf(source_path, "%s/%s", source_dir, source_file);
    }
    build_opts = (char *)malloc(sdir_len + strlen(build_option) + 4);
    sprintf(build_opts, "%s -I%s", build_option, source_dir);
  }
  size_t source_len;
  char *source_code = clu_LoadProgSource(source_path, &source_len);
  program = clCreateProgramWithSource(context, 1, (const char **)&source_code,
                                      &source_len, &err_code);
  free(source_code);
  clu_CheckErrorInternal(
      err_code, "clCreateProgramWithSource()",
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/dividiti/pencil-benchmark/refs/heads/master/"
      "NAS/OpenCL/common/cl_util.c",
      372);
  err_code = clBuildProgram(program, 1, &device, build_opts, NULL, NULL);
  if (err_code != CL_SUCCESS) {
    clu_PrintBuildLog(program, device);
    clu_CheckErrorInternal(
        err_code, "clBuldProgram()",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/dividiti/pencil-benchmark/refs/heads/master/"
        "NAS/OpenCL/common/cl_util.c",
        378);
  }
  if (sdir_len > 0) {
    free(source_path);
    free(build_opts);
  }
  return program;
}


x86 assembly (clang, -O0):
<clu_MakeProgram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jbe    12a7 <clu_MakeProgram+0x117>
mov    -0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    122d <clu_MakeProgram+0x9d>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xddd(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    126a <clu_MakeProgram+0xda>
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x68(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xda0(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%rdi
add    %rax,%rdi
add    $0x4,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd69(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <clu_LoadProgSource@plt>
mov    %rax,-0x58(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
lea    -0x58(%rbp),%rdx
lea    -0x50(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,-0x24(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
lea    0xd2b(%rip),%rsi
lea    0xd40(%rip),%rdx
mov    $0x174,%ecx
call   1080 <clu_CheckErrorInternal@plt>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
lea    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1030 <clBuildProgram@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2cbb(%rip),%rcx
cmp    (%rcx),%rax
je     1355 <clu_MakeProgram+0x1c5>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <clu_PrintBuildLog@plt>
mov    -0x30(%rbp),%rdi
lea    0xd8d(%rip),%rsi
lea    0xce4(%rip),%rdx
mov    $0x17a,%ecx
call   1080 <clu_CheckErrorInternal@plt>
cmpq   $0x0,-0x48(%rbp)
jbe    1372 <clu_MakeProgram+0x1e2>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clu_MakeProgram>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %edi,%ebx
mov    %esi,0x4(%rsp)
mov    %rdx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r12
test   %rax,%rax
je     124c <clu_MakeProgram+0xbc>
mov    %ebx,0x14(%rsp)
mov    -0x1(%r12,%rbp,1),%bl
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    $0x2f,%bl
jne    11f0 <clu_MakeProgram+0x60>
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0xe12(%rip),%rsi
jmp    1207 <clu_MakeProgram+0x77>
lea    (%r12,%rax,1),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0xdfe(%rip),%rsi
mov    %rax,%rdi
mov    %rbp,%rdx
mov    %r15,%rcx
call   10a0 <sprintf@plt>
mov    %r13,%r15
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x4,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xdd4(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbp,%rcx
call   10a0 <sprintf@plt>
mov    %rbx,%r14
mov    0x14(%rsp),%ebx
lea    0x20(%rsp),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1090 <clu_LoadProgSource@plt>
mov    %rax,0x18(%rsp)
lea    0x18(%rsp),%rdx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    $0x1,%esi
mov    %rbp,%rcx
call   1050 <clCreateProgramWithSource@plt>
mov    %eax,%ebp
mov    0x18(%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
lea    0xd81(%rip),%rsi
lea    0xd96(%rip),%rdx
mov    $0x174,%ecx
call   1080 <clu_CheckErrorInternal@plt>
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
mov    $0x1,%esi
mov    %r14,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <clBuildProgram@plt>
mov    %rax,0x8(%rsp)
mov    0x2d17(%rip),%rcx
cmp    (%rcx),%rax
je     12f6 <clu_MakeProgram+0x166>
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   10b0 <clu_PrintBuildLog@plt>
mov    0x8(%rsp),%rdi
lea    0xdec(%rip),%rsi
lea    0xd43(%rip),%rdx
mov    $0x17a,%ecx
call   1080 <clu_CheckErrorInternal@plt>
test   %r12,%r12
je     130b <clu_MakeProgram+0x17b>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [8 x i8] c"%s -I%s\00"
@.str.3 = [28 x i8] c"clCreateProgramWithSource()\00"
@.str.4 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dividiti/pencil-benchmark/refs/heads/master/NAS/OpenCL/common/cl_util.c\00"
@CL_SUCCESS = global i64 0
@.str.5 = [16 x i8] c"clBuldProgram()\00"
define i32 @clu_MakeProgram(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i8*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%18 = load i8*, i8** %9
store i8* %18, i8** %13
%19 = load i8*, i8** %10
store i8* %19, i8** %14
%20 = load i8*, i8** %8
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %15
%22 = load i64, i64* %15
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %68
24: ; preds = %5
%25 = load i8*, i8** %8
%26 = load i64, i64* %15
%27 = sub i64 %26, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
br i1 %31, label %32, label %44
32: ; preds = %24
%33 = load i64, i64* %15
%34 = load i8*, i8** %9
%35 = call i64 @strlen(i8* %34)
%36 = add i64 %33, %35
%37 = add i64 %36, 1
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %13
%40 = load i8*, i8** %13
%41 = load i8*, i8** %8
%42 = load i8*, i8** %9
%43 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %42)
br label %56
44: ; preds = %24
%45 = load i64, i64* %15
%46 = load i8*, i8** %9
%47 = call i64 @strlen(i8* %46)
%48 = add i64 %45, %47
%49 = add i64 %48, 2
%50 = call i64 @malloc(i64 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %13
%52 = load i8*, i8** %13
%53 = load i8*, i8** %8
%54 = load i8*, i8** %9
%55 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %54)
br label %56
56: ; preds = %44, %32
%57 = load i64, i64* %15
%58 = load i8*, i8** %10
%59 = call i64 @strlen(i8* %58)
%60 = add i64 %57, %59
%61 = add i64 %60, 4
%62 = call i64 @malloc(i64 %61)
%63 = inttoptr i64 %62 to i8*
store i8* %63, i8** %14
%64 = load i8*, i8** %14
%65 = load i8*, i8** %10
%66 = load i8*, i8** %8
%67 = call i32 @sprintf(i8* %64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %65, i8* %66)
br label %68
68: ; preds = %56, %5
%69 = load i8*, i8** %13
%70 = call i8* @clu_LoadProgSource(i8* %69, i64* %16)
store i8* %70, i8** %17
%71 = load i32, i32* %6
%72 = call i32 @clCreateProgramWithSource(i32 %71, i32 1, i8** %17, i64* %16, i64* %12)
store i32 %72, i32* %11
%73 = load i8*, i8** %17
%74 = call i32 @free(i8* %73)
%75 = load i64, i64* %12
%76 = call i32 @clu_CheckErrorInternal(i64 %75, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.4, i64 0, i64 0), i32 372)
%77 = load i32, i32* %11
%78 = load i8*, i8** %14
%79 = call i64 @clBuildProgram(i32 %77, i32 1, i32* %7, i8* %78, i32* null, i32* null)
store i64 %79, i64* %12
%80 = load i64, i64* %12
%81 = load i64, i64* @CL_SUCCESS
%82 = icmp ne i64 %80, %81
br i1 %82, label %83, label %89
83: ; preds = %68
%84 = load i32, i32* %11
%85 = load i32, i32* %7
%86 = call i32 @clu_PrintBuildLog(i32 %84, i32 %85)
%87 = load i64, i64* %12
%88 = call i32 @clu_CheckErrorInternal(i64 %87, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.4, i64 0, i64 0), i32 378)
br label %89
89: ; preds = %83, %68
%90 = load i64, i64* %15
%91 = icmp ugt i64 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %89
%93 = load i8*, i8** %13
%94 = call i32 @free(i8* %93)
%95 = load i8*, i8** %14
%96 = call i32 @free(i8* %95)
br label %97
97: ; preds = %92, %89
%98 = load i32, i32* %11
ret i32 %98
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [8 x i8] c"%s -I%s\00"
@.str.3 = [28 x i8] c"clCreateProgramWithSource()\00"
@.str.4 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dividiti/pencil-benchmark/refs/heads/master/NAS/OpenCL/common/cl_util.c\00"
@CL_SUCCESS = global i64 0
@.str.5 = [16 x i8] c"clBuldProgram()\00"
define i32 @clu_MakeProgram(i32 %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 %1, i32* %6
%10 = bitcast i64* %7 to i8*
%11 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %39, label %13
13: ; preds = %5
%14 = add i64 %11, -1
%15 = getelementptr inbounds i8, i8* %2, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
%18 = tail call i64 @strlen(i8* dereferenceable(1) %3)
br i1 %17, label %19, label %25
19: ; preds = %13
%20 = add i64 %11, 1
%21 = add i64 %20, %18
%22 = tail call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %3)
br label %31
25: ; preds = %13
%26 = add i64 %11, 2
%27 = add i64 %26, %18
%28 = tail call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
br label %31
31: ; preds = %25, %19
%32 = phi i8* [ %23, %19 ], [ %29, %25 ]
%33 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%34 = add i64 %11, 4
%35 = add i64 %34, %33
%36 = tail call i64 @malloc(i64 %35)
%37 = inttoptr i64 %36 to i8*
%38 = tail call i32 @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %2)
br label %39
39: ; preds = %31, %5
%40 = phi i8* [ %37, %31 ], [ %4, %5 ]
%41 = phi i8* [ %32, %31 ], [ %3, %5 ]
%42 = bitcast i64* %8 to i8*
%43 = bitcast i8** %9 to i8*
%44 = call i8* @clu_LoadProgSource(i8* %41, i64* %8)
store i8* %44, i8** %9
%45 = call i32 @clCreateProgramWithSource(i32 %0, i32 1, i8** %9, i64* %8, i64* %7)
%46 = load i8*, i8** %9
%47 = call i32 @free(i8* %46)
%48 = load i64, i64* %7
%49 = call i32 @clu_CheckErrorInternal(i64 %48, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.4, i64 0, i64 0), i32 372)
%50 = call i64 @clBuildProgram(i32 %45, i32 1, i32* %6, i8* %40, i32* null, i32* null)
store i64 %50, i64* %7
%51 = load i64, i64* @CL_SUCCESS
%52 = icmp eq i64 %50, %51
br i1 %52, label %58, label %53
53: ; preds = %39
%54 = load i32, i32* %6
%55 = call i32 @clu_PrintBuildLog(i32 %45, i32 %54)
%56 = load i64, i64* %7
%57 = call i32 @clu_CheckErrorInternal(i64 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.4, i64 0, i64 0), i32 378)
br label %58
58: ; preds = %53, %39
br i1 %12, label %62, label %59
59: ; preds = %58
%60 = call i32 @free(i8* %41)
%61 = call i32 @free(i8* %40)
br label %62
62: ; preds = %59, %58
ret i32 %45
}