#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*/ max_mem_alloc_size;
typedef int /*<<< orphan*/ global_memsize;
typedef size_t cl_uint;
typedef int /*<<< orphan*/ cl_platform_id;
typedef int cl_long;
typedef scalar_t__ cl_int;
typedef int /*<<< orphan*/ cl_device_id;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_GLOBAL_MEM_SIZE;
int /*<<< orphan*/ CL_DEVICE_MAX_MEM_ALLOC_SIZE;
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
scalar_t__ CL_SUCCESS;
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, size_t *);
scalar_t__ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int, int *,
                           int /*<<< orphan*/ *);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, size_t *);
int main(void) {
  cl_int err;
  cl_platform_id platforms[32];
  cl_uint nplatforms;
  cl_device_id devices[32];
  cl_uint ndevices;
  cl_uint i, j;
  err = clGetPlatformIDs(32, platforms, &nplatforms);
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;
  for (i = 0; i < nplatforms; i++) {
    err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 32, devices,
                         &ndevices);
    if (err != CL_SUCCESS)
      return EXIT_FAILURE;
    for (j = 0; j < ndevices; j++) {
      cl_long global_memsize, max_mem_alloc_size, min_max_mem_alloc_size;
      err = clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE,
                            sizeof(global_memsize), &global_memsize, NULL);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      err = clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE,
                            sizeof(max_mem_alloc_size), &max_mem_alloc_size,
                            NULL);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;
      if (global_memsize == 0)
        return EXIT_FAILURE;
      min_max_mem_alloc_size = 128 * 1024 * 1024;
      if (min_max_mem_alloc_size < global_memsize / 4)
        min_max_mem_alloc_size = global_memsize / 4;
      if (max_mem_alloc_size < min_max_mem_alloc_size)
        return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rsi
mov    $0x20,%edi
lea    -0x98(%rbp),%rdx
call   1050 <clGetPlatformIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
je     1183 <main+0x53>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
movq   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%rax
cmp    -0x98(%rbp),%rax
jae    1386 <main+0x256>
mov    -0x130(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    -0x120(%rbp),%rcx
mov    $0x20,%edx
lea    -0x128(%rbp),%r8
call   1030 <clGetDeviceIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rax
je     11fa <main+0xca>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
movq   $0x0,-0x138(%rbp)
mov    -0x138(%rbp),%rax
cmp    -0x128(%rbp),%rax
jae    136a <main+0x23a>
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    -0x13c(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceInfo@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d6b(%rip),%rcx
cmp    (%rcx),%rax
je     126f <main+0x13f>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
mov    -0x138(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%edi
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    -0x140(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <clGetDeviceInfo@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d15(%rip),%rcx
cmp    (%rcx),%rax
je     12c5 <main+0x195>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
cmpl   $0x0,-0x13c(%rbp)
jne    12e3 <main+0x1b3>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
movl   $0x8000000,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    %eax,-0x148(%rbp)
mov    -0x13c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x148(%rbp),%eax
cmp    %ecx,%eax
jge    132b <main+0x1fb>
mov    -0x13c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x144(%rbp)
mov    -0x140(%rbp),%eax
cmp    -0x144(%rbp),%eax
jge    134e <main+0x21e>
mov    0x2c8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1392 <main+0x262>
jmp    1353 <main+0x223>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    1205 <main+0xd5>
jmp    136f <main+0x23f>
mov    -0x130(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x130(%rbp)
jmp    118e <main+0x5e>
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
lea    0xa0(%rsp),%rsi
lea    0x18(%rsp),%rdx
mov    $0x20,%edi
call   1050 <clGetPlatformIDs@plt>
mov    0x2e61(%rip),%r12
cmp    (%r12),%rax
jne    126f <main+0x13f>
cmpq   $0x0,0x18(%rsp)
je     1266 <main+0x136>
xor    %r14d,%r14d
mov    0x2e61(%rip),%rax
lea    0x20(%rsp),%rbp
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r13
mov    0xa0(%rsp,%r14,4),%edi
mov    (%rax),%esi
mov    $0x20,%edx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1030 <clGetDeviceIDs@plt>
cmp    (%r12),%rax
jne    126f <main+0x13f>
cmpq   $0x0,0x10(%rsp)
je     1250 <main+0x120>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x20(%rsp,%r15,4),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1040 <clGetDeviceInfo@plt>
cmp    (%r12),%rax
jne    126f <main+0x13f>
mov    0x20(%rsp,%r15,4),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
lea    0x8(%rsp),%rcx
xor    %r8d,%r8d
call   1040 <clGetDeviceInfo@plt>
cmp    (%r12),%rax
jne    126f <main+0x13f>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     126f <main+0x13f>
mov    $0x8000000,%ecx
cmp    $0x20000004,%eax
jl     1239 <main+0x109>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x2,%ecx
cmp    %ecx,0x8(%rsp)
jl     126f <main+0x13f>
add    $0x1,%r15
cmp    0x10(%rsp),%r15
jb     11d0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    0x18(%rsp),%r14
mov    0x2d80(%rip),%rax
jb     118e <main+0x5e>
mov    0x2d5b(%rip),%rax
jmp    1276 <main+0x146>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_DEVICE_GLOBAL_MEM_SIZE = global i32 0
@CL_DEVICE_MAX_MEM_ALLOC_SIZE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [32 x i32]
%4 = alloca i64
%5 = alloca [32 x i32]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%13 = call i64 @clGetPlatformIDs(i32 32, i32* %12, i64* %4)
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = load i64, i64* @CL_SUCCESS
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %1
br label %92
19: ; preds = %0
store i64 0, i64* %7
br label %20
20: ; preds = %87, %19
%21 = load i64, i64* %7
%22 = load i64, i64* %4
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %90
24: ; preds = %20
%25 = load i64, i64* %7
%26 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* @CL_DEVICE_TYPE_ALL
%29 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 0
%30 = call i64 @clGetDeviceIDs(i32 %27, i32 %28, i32 32, i32* %29, i64* %6)
store i64 %30, i64* %2
%31 = load i64, i64* %2
%32 = load i64, i64* @CL_SUCCESS
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %1
br label %92
36: ; preds = %24
store i64 0, i64* %8
br label %37
37: ; preds = %83, %36
%38 = load i64, i64* %8
%39 = load i64, i64* %6
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %86
41: ; preds = %37
%42 = load i64, i64* %8
%43 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* @CL_DEVICE_GLOBAL_MEM_SIZE
%46 = call i64 @clGetDeviceInfo(i32 %44, i32 %45, i32 4, i32* %9, i32* null)
store i64 %46, i64* %2
%47 = load i64, i64* %2
%48 = load i64, i64* @CL_SUCCESS
%49 = icmp ne i64 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %1
br label %92
52: ; preds = %41
%53 = load i64, i64* %8
%54 = getelementptr inbounds [32 x i32], [32 x i32]* %5, i64 0, i64 %53
%55 = load i32, i32* %54
%56 = load i32, i32* @CL_DEVICE_MAX_MEM_ALLOC_SIZE
%57 = call i64 @clGetDeviceInfo(i32 %55, i32 %56, i32 4, i32* %10, i32* null)
store i64 %57, i64* %2
%58 = load i64, i64* %2
%59 = load i64, i64* @CL_SUCCESS
%60 = icmp ne i64 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = load i32, i32* @EXIT_FAILURE
store i32 %62, i32* %1
br label %92
63: ; preds = %52
%64 = load i32, i32* %9
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = load i32, i32* @EXIT_FAILURE
store i32 %67, i32* %1
br label %92
68: ; preds = %63
store i32 134217728, i32* %11
%69 = load i32, i32* %11
%70 = load i32, i32* %9
%71 = sdiv i32 %70, 4
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = load i32, i32* %9
%75 = sdiv i32 %74, 4
store i32 %75, i32* %11
br label %76
76: ; preds = %73, %68
%77 = load i32, i32* %10
%78 = load i32, i32* %11
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = load i32, i32* @EXIT_FAILURE
store i32 %81, i32* %1
br label %92
82: ; preds = %76
br label %83
83: ; preds = %82
%84 = load i64, i64* %8
%85 = add i64 %84, 1
store i64 %85, i64* %8
br label %37
86: ; preds = %37
br label %87
87: ; preds = %86
%88 = load i64, i64* %7
%89 = add i64 %88, 1
store i64 %89, i64* %7
br label %20
90: ; preds = %20
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %1
br label %92
92: ; preds = %90, %80, %66, %61, %50, %34, %17
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@CL_DEVICE_GLOBAL_MEM_SIZE = global i32 0
@CL_DEVICE_MAX_MEM_ALLOC_SIZE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [32 x i32]
%2 = alloca i64
%3 = alloca [32 x i32]
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [32 x i32]* %1 to i8*
%8 = bitcast i64* %2 to i8*
%9 = bitcast [32 x i32]* %3 to i8*
%10 = bitcast i64* %4 to i8*
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 0
%12 = call i64 @clGetPlatformIDs(i32 32, i32* %11, i64* %2)
%13 = load i64, i64* @CL_SUCCESS
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %0
%16 = load i64, i64* %2
%17 = icmp eq i64 %16, 0
br i1 %17, label %71, label %18
18: ; preds = %15
%19 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%20 = bitcast i32* %5 to i8*
%21 = bitcast i32* %6 to i8*
br label %24
22: ; preds = %0
%23 = load i32, i32* @EXIT_FAILURE
br label %73
24: ; preds = %18, %67
%25 = phi i64 [ 0, %18 ], [ %68, %67 ]
%26 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* @CL_DEVICE_TYPE_ALL
%29 = call i64 @clGetDeviceIDs(i32 %27, i32 %28, i32 32, i32* %19, i64* %4)
%30 = load i64, i64* @CL_SUCCESS
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i64, i64* %4
%34 = icmp eq i64 %33, 0
br i1 %34, label %67, label %40
35: ; preds = %24
%36 = load i32, i32* @EXIT_FAILURE
br label %73
37: ; preds = %59
%38 = load i64, i64* %4
%39 = icmp ult i64 %66, %38
br i1 %39, label %40, label %67
40: ; preds = %32, %37
%41 = phi i64 [ %66, %37 ], [ 0, %32 ]
%42 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* @CL_DEVICE_GLOBAL_MEM_SIZE
%45 = call i64 @clGetDeviceInfo(i32 %43, i32 %44, i32 4, i32* %5, i32* null)
%46 = load i64, i64* @CL_SUCCESS
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %57
48: ; preds = %40
%49 = load i32, i32* %42
%50 = load i32, i32* @CL_DEVICE_MAX_MEM_ALLOC_SIZE
%51 = call i64 @clGetDeviceInfo(i32 %49, i32 %50, i32 4, i32* %6, i32* null)
%52 = load i64, i64* @CL_SUCCESS
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* %5
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54, %48, %40
%58 = load i32, i32* @EXIT_FAILURE
br label %73
59: ; preds = %54
%60 = icmp sgt i32 %55, 536870915
%61 = sdiv i32 %55, 4
%62 = select i1 %60, i32 %61, i32 134217728
%63 = load i32, i32* %6
%64 = icmp slt i32 %63, %62
%65 = load i32, i32* @EXIT_FAILURE
%66 = add nuw i64 %41, 1
br i1 %64, label %73, label %37
67: ; preds = %37, %32
%68 = add nuw i64 %25, 1
%69 = load i64, i64* %2
%70 = icmp ult i64 %68, %69
br i1 %70, label %24, label %71
71: ; preds = %67, %15
%72 = load i32, i32* @EXIT_SUCCESS
br label %73
73: ; preds = %59, %57, %71, %35, %22
%74 = phi i32 [ %23, %22 ], [ %36, %35 ], [ %72, %71 ], [ %58, %57 ], [ %65, %59 ]
ret i32 %74
}