#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 cl_uint;
typedef int /*<<< orphan*/ cl_platform_id;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_device_type;
typedef int /*<<< orphan*/ cl_device_id;
typedef scalar_t__ cl_bool;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_AVAILABLE;
scalar_t__ CL_DEVICE_NOT_FOUND;
scalar_t__ CL_SUCCESS;
scalar_t__ CL_TRUE;
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, int *);
scalar_t__ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int,
                           scalar_t__ *, int /*<<< orphan*/ *);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ clu_CheckErrorInternal(scalar_t__, char *, char *, int);
int /*<<< orphan*/ clu_Exit(char *, ...);
int /*<<< orphan*/ clu_GetDeviceTypeName(int /*<<< orphan*/);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
cl_device_id clu_GetAvailableDevice(cl_device_type device_type) {
  cl_platform_id *platforms;
  cl_uint num_platforms = 0;
  cl_device_id *devices;
  cl_uint num_devices;
  cl_int err_code;
  cl_uint i, k;
  err_code = clGetPlatformIDs(0, NULL, &num_platforms);
  if (num_platforms == 0)
    clu_Exit("No OpenCL platform!\n");
  platforms = (cl_platform_id *)malloc(num_platforms * sizeof(cl_platform_id));
  err_code = clGetPlatformIDs(num_platforms, platforms, NULL);
  clu_CheckErrorInternal(
      err_code, "clGetPlatformIDs()",
      "/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",
      157);
  for (i = 0; i < num_platforms; i++) {
    err_code = clGetDeviceIDs(platforms[i], device_type, 0, NULL, &num_devices);
    if (err_code != CL_SUCCESS && err_code != CL_DEVICE_NOT_FOUND)
      clu_CheckErrorInternal(
          err_code, "clGetDeviceIDs for num_devices",
          "/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",
          165);
    if (num_devices > 0) {
      devices = (cl_device_id *)malloc(num_devices * sizeof(cl_device_id));
      err_code =
          clGetDeviceIDs(platforms[i], device_type, num_devices, devices, NULL);
      clu_CheckErrorInternal(
          err_code, "clGetDeviceIDs()",
          "/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",
          172);
      for (k = 0; k < num_devices; k++) {
        cl_bool available;
        err_code = clGetDeviceInfo(devices[k], CL_DEVICE_AVAILABLE,
                                   sizeof(cl_bool), &available, NULL);
        clu_CheckErrorInternal(
            err_code, "clGetDeviceInfo()",
            "/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",
            181);
        if (available == CL_TRUE) {
          cl_device_id ret_device = devices[k];
          free(devices);
          free(platforms);
          return ret_device;
        }
      }
      free(devices);
    }
  }
  free(platforms);
  clu_Exit("ERROR: No device for %s\n", clu_GetDeviceTypeName(device_type));
  return 0;
}


x86 assembly (clang, -O0):
<clu_GetAvailableDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x14(%rbp),%rdx
call   1060 <clGetPlatformIDs@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11bd <clu_GetAvailableDevice+0x3d>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1070 <clu_Exit@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <clGetPlatformIDs@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    0xe32(%rip),%rdx
mov    $0x9d,%ecx
call   1090 <clu_CheckErrorInternal@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    139c <clu_GetAvailableDevice+0x21c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x24(%rbp),%r8
call   1040 <clGetDeviceIDs@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%rax
je     1278 <clu_GetAvailableDevice+0xf8>
mov    -0x30(%rbp),%rax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%rax
je     1278 <clu_GetAvailableDevice+0xf8>
mov    -0x30(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    0xdba(%rip),%rdx
mov    $0xa5,%ecx
call   1090 <clu_CheckErrorInternal@plt>
cmpl   $0x0,-0x24(%rbp)
jle    1389 <clu_GetAvailableDevice+0x209>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x8(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceIDs@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    0xd5e(%rip),%rdx
mov    $0xac,%ecx
call   1090 <clu_CheckErrorInternal@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1380 <clu_GetAvailableDevice+0x200>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    0x2cdf(%rip),%rax
mov    (%rax),%esi
mov    $0x8,%edx
lea    -0x40(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <clGetDeviceInfo@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xddd(%rip),%rsi
lea    0xd04(%rip),%rdx
mov    $0xb5,%ecx
call   1090 <clu_CheckErrorInternal@plt>
mov    -0x40(%rbp),%rax
mov    0x2caf(%rip),%rcx
cmp    (%rcx),%rax
jne    136d <clu_GetAvailableDevice+0x1ed>
mov    -0x20(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13c4 <clu_GetAvailableDevice+0x244>
jmp    1372 <clu_GetAvailableDevice+0x1f2>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12db <clu_GetAvailableDevice+0x15b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    138e <clu_GetAvailableDevice+0x20e>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1207 <clu_GetAvailableDevice+0x87>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
call   10a0 <clu_GetDeviceTypeName@plt>
mov    %eax,%esi
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1070 <clu_Exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clu_GetAvailableDevice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r12d
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <clGetPlatformIDs@plt>
mov    0x8(%rsp),%edi
test   %edi,%edi
jne    11c1 <clu_GetAvailableDevice+0x41>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1070 <clu_Exit@plt>
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    0x8(%rsp),%edi
mov    %rax,0x10(%rsp)
mov    %rax,%rsi
xor    %edx,%edx
call   1060 <clGetPlatformIDs@plt>
lea    0xe32(%rip),%rsi
lea    0xe3e(%rip),%rdx
mov    %rax,%rdi
mov    $0x9d,%ecx
call   1090 <clu_CheckErrorInternal@plt>
cmpl   $0x0,0x8(%rsp)
jle    135c <clu_GetAvailableDevice+0x1dc>
xor    %r13d,%r13d
lea    0xc(%rsp),%rbx
mov    0x2db7(%rip),%rbp
lea    0xe10(%rip),%r15
mov    %r12d,0x1c(%rsp)
jmp    1246 <clu_GetAvailableDevice+0xc6>
nop
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x1c(%rsp),%r12d
mov    0x2d94(%rip),%rbp
add    $0x1,%r13
movslq 0x8(%rsp),%rax
cmp    %rax,%r13
jge    135c <clu_GetAvailableDevice+0x1dc>
mov    0x10(%rsp),%rax
mov    (%rax,%r13,4),%edi
mov    %r12d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1040 <clGetDeviceIDs@plt>
cmp    0x0(%rbp),%rax
je     1287 <clu_GetAvailableDevice+0x107>
mov    0x2d75(%rip),%rcx
cmp    (%rcx),%rax
je     1287 <clu_GetAvailableDevice+0x107>
mov    %rax,%rdi
lea    0xe50(%rip),%rsi
mov    %r15,%rdx
mov    $0xa5,%ecx
call   1090 <clu_CheckErrorInternal@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    1234 <clu_GetAvailableDevice+0xb4>
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    0x10(%rsp),%rax
mov    (%rax,%r13,4),%edi
mov    0xc(%rsp),%edx
mov    %r12d,%esi
mov    %r14,%rcx
xor    %r8d,%r8d
call   1040 <clGetDeviceIDs@plt>
mov    %rax,%rdi
lea    0xe2a(%rip),%rsi
mov    %r15,%rdx
mov    $0xac,%ecx
call   1090 <clu_CheckErrorInternal@plt>
cmpl   $0x0,0xc(%rsp)
mov    0x2d00(%rip),%rbp
jle    1220 <clu_GetAvailableDevice+0xa0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%r12,4),%edi
mov    0x0(%rbp),%esi
mov    $0x8,%edx
lea    0x20(%rsp),%rcx
xor    %r8d,%r8d
call   1050 <clGetDeviceInfo@plt>
mov    %rax,%rdi
lea    0xde7(%rip),%rsi
mov    %r15,%rdx
mov    $0xb5,%ecx
call   1090 <clu_CheckErrorInternal@plt>
mov    0x20(%rsp),%rax
mov    0x2cbc(%rip),%rcx
cmp    (%rcx),%rax
je     1344 <clu_GetAvailableDevice+0x1c4>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
cmp    %rax,%r12
jl     12f0 <clu_GetAvailableDevice+0x170>
jmp    1220 <clu_GetAvailableDevice+0xa0>
mov    (%r14,%r12,4),%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
jmp    1380 <clu_GetAvailableDevice+0x200>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r12d,%edi
call   10a0 <clu_GetDeviceTypeName@plt>
lea    0xd97(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <clu_Exit@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"No OpenCL platform!\0A\00"
@.str.1 = [19 x i8] c"clGetPlatformIDs()\00"
@.str.2 = [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
@CL_DEVICE_NOT_FOUND = global i64 0
@.str.3 = [31 x i8] c"clGetDeviceIDs for num_devices\00"
@.str.4 = [17 x i8] c"clGetDeviceIDs()\00"
@CL_DEVICE_AVAILABLE = global i32 0
@.str.5 = [18 x i8] c"clGetDeviceInfo()\00"
@CL_TRUE = global i64 0
@.str.6 = [25 x i8] c"ERROR: No device for %s\0A\00"
define i32 @clu_GetAvailableDevice(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%13 = call i64 @clGetPlatformIDs(i32 0, i32* null, i32* %5)
store i64 %13, i64* %8
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 (i8*, ...) @clu_Exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 4
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i32*
store i32* %24, i32** %4
%25 = load i32, i32* %5
%26 = load i32*, i32** %4
%27 = call i64 @clGetPlatformIDs(i32 %25, i32* %26, i32* null)
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = call i32 @clu_CheckErrorInternal(i64 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 157)
store i32 0, i32* %9
br label %30
30: ; preds = %109, %18
%31 = load i32, i32* %9
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %112
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32, i32* %3
%41 = call i64 @clGetDeviceIDs(i32 %39, i32 %40, i32 0, i32* null, i32* %7)
store i64 %41, i64* %8
%42 = load i64, i64* %8
%43 = load i64, i64* @CL_SUCCESS
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %52
45: ; preds = %34
%46 = load i64, i64* %8
%47 = load i64, i64* @CL_DEVICE_NOT_FOUND
%48 = icmp ne i64 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = load i64, i64* %8
%51 = call i32 @clu_CheckErrorInternal(i64 %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 165)
br label %52
52: ; preds = %49, %45, %34
%53 = load i32, i32* %7
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %108
55: ; preds = %52
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i32*
store i32* %61, i32** %6
%62 = load i32*, i32** %4
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
%66 = load i32, i32* %65
%67 = load i32, i32* %3
%68 = load i32, i32* %7
%69 = load i32*, i32** %6
%70 = call i64 @clGetDeviceIDs(i32 %66, i32 %67, i32 %68, i32* %69, i32* null)
store i64 %70, i64* %8
%71 = load i64, i64* %8
%72 = call i32 @clu_CheckErrorInternal(i64 %71, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 172)
store i32 0, i32* %10
br label %73
73: ; preds = %102, %55
%74 = load i32, i32* %10
%75 = load i32, i32* %7
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %105
77: ; preds = %73
%78 = load i32*, i32** %6
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = load i32, i32* @CL_DEVICE_AVAILABLE
%84 = call i64 @clGetDeviceInfo(i32 %82, i32 %83, i32 8, i64* %11, i32* null)
store i64 %84, i64* %8
%85 = load i64, i64* %8
%86 = call i32 @clu_CheckErrorInternal(i64 %85, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 181)
%87 = load i64, i64* %11
%88 = load i64, i64* @CL_TRUE
%89 = icmp eq i64 %87, %88
br i1 %89, label %90, label %101
90: ; preds = %77
%91 = load i32*, i32** %6
%92 = load i32, i32* %10
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
store i32 %95, i32* %12
%96 = load i32*, i32** %6
%97 = call i32 @free(i32* %96)
%98 = load i32*, i32** %4
%99 = call i32 @free(i32* %98)
%100 = load i32, i32* %12
store i32 %100, i32* %2
br label %118
101: ; preds = %77
br label %102
102: ; preds = %101
%103 = load i32, i32* %10
%104 = add nsw i32 %103, 1
store i32 %104, i32* %10
br label %73
105: ; preds = %73
%106 = load i32*, i32** %6
%107 = call i32 @free(i32* %106)
br label %108
108: ; preds = %105, %52
br label %109
109: ; preds = %108
%110 = load i32, i32* %9
%111 = add nsw i32 %110, 1
store i32 %111, i32* %9
br label %30
112: ; preds = %30
%113 = load i32*, i32** %4
%114 = call i32 @free(i32* %113)
%115 = load i32, i32* %3
%116 = call i32 @clu_GetDeviceTypeName(i32 %115)
%117 = call i32 (i8*, ...) @clu_Exit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %116)
store i32 0, i32* %2
br label %118
118: ; preds = %112, %90
%119 = load i32, i32* %2
ret i32 %119
}

LLVM IR (-O2):
@.str = [21 x i8] c"No OpenCL platform!\0A\00"
@.str.1 = [19 x i8] c"clGetPlatformIDs()\00"
@.str.2 = [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
@CL_DEVICE_NOT_FOUND = global i64 0
@.str.3 = [31 x i8] c"clGetDeviceIDs for num_devices\00"
@.str.4 = [17 x i8] c"clGetDeviceIDs()\00"
@CL_DEVICE_AVAILABLE = global i32 0
@.str.5 = [18 x i8] c"clGetDeviceInfo()\00"
@CL_TRUE = global i64 0
@.str.6 = [25 x i8] c"ERROR: No device for %s\0A\00"
define i32 @clu_GetAvailableDevice(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
%7 = call i64 @clGetPlatformIDs(i32 0, i32* null, i32* %2)
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 (i8*, ...) @clu_Exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %2
br label %13
13: ; preds = %10, %1
%14 = phi i32 [ %12, %10 ], [ %8, %1 ]
%15 = shl i32 %14, 2
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
%18 = load i32, i32* %2
%19 = call i64 @clGetPlatformIDs(i32 %18, i32* %17, i32* null)
%20 = call i32 @clu_CheckErrorInternal(i64 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 157)
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %79
23: ; preds = %13
%24 = bitcast i64* %4 to i8*
br label %25
25: ; preds = %23, %74
%26 = phi i64 [ 0, %23 ], [ %75, %74 ]
%27 = getelementptr inbounds i32, i32* %17, i64 %26
%28 = load i32, i32* %27
%29 = call i64 @clGetDeviceIDs(i32 %28, i32 %0, i32 0, i32* null, i32* %3)
%30 = load i64, i64* @CL_SUCCESS
%31 = icmp eq i64 %29, %30
%32 = load i64, i64* @CL_DEVICE_NOT_FOUND
%33 = icmp eq i64 %29, %32
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %37, label %35
35: ; preds = %25
%36 = call i32 @clu_CheckErrorInternal(i64 %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 165)
br label %37
37: ; preds = %35, %25
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %74
40: ; preds = %37
%41 = shl i32 %38, 2
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i32*
%44 = load i32, i32* %27
%45 = load i32, i32* %3
%46 = call i64 @clGetDeviceIDs(i32 %44, i32 %0, i32 %45, i32* %43, i32* null)
%47 = call i32 @clu_CheckErrorInternal(i64 %46, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 172)
%48 = load i32, i32* %3
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %72
50: ; preds = %40, %67
%51 = phi i64 [ %68, %67 ], [ 0, %40 ]
%52 = getelementptr inbounds i32, i32* %43, i64 %51
%53 = load i32, i32* %52
%54 = load i32, i32* @CL_DEVICE_AVAILABLE
%55 = call i64 @clGetDeviceInfo(i32 %53, i32 %54, i32 8, i64* %4, i32* null)
%56 = call i32 @clu_CheckErrorInternal(i64 %55, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.2, i64 0, i64 0), i32 181)
%57 = load i64, i64* %4
%58 = load i64, i64* @CL_TRUE
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %50
%61 = inttoptr i64 %42 to i32*
%62 = and i64 %51, 4294967295
%63 = getelementptr inbounds i32, i32* %61, i64 %62
%64 = load i32, i32* %63
%65 = call i32 @free(i32* %61)
%66 = call i32 @free(i32* %17)
br label %83
67: ; preds = %50
%68 = add nuw nsw i64 %51, 1
%69 = load i32, i32* %3
%70 = sext i32 %69 to i64
%71 = icmp slt i64 %68, %70
br i1 %71, label %50, label %72
72: ; preds = %67, %40
%73 = call i32 @free(i32* %43)
br label %74
74: ; preds = %37, %72
%75 = add nuw nsw i64 %26, 1
%76 = load i32, i32* %2
%77 = sext i32 %76 to i64
%78 = icmp slt i64 %75, %77
br i1 %78, label %25, label %79
79: ; preds = %74, %13
%80 = call i32 @free(i32* %17)
%81 = call i32 @clu_GetDeviceTypeName(i32 %0)
%82 = call i32 (i8*, ...) @clu_Exit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %60, %79
%84 = phi i32 [ 0, %79 ], [ %64, %60 ]
ret i32 %84
}