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

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_ALL;
int /*<<< orphan*/ CL_MEM_OBJECT_IMAGE2D;
scalar_t__ CL_SUCCESS;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ clCreateContext(int /*<<< orphan*/ *, int,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, scalar_t__ *);
scalar_t__ clGetDeviceIDs(int /*<<< orphan*/, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *, int *);
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ clGetSupportedImageFormats(int /*<<< orphan*/,
                                              int /*<<< orphan*/,
                                              int /*<<< orphan*/, int,
                                              int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int main(void) {
  cl_int err;
  cl_platform_id platform[1];
  cl_uint nplatforms;
  cl_device_id devices[2];
  cl_uint ndevices;
  cl_image_format *img_formats;
  cl_uint num_entries;
  err = clGetPlatformIDs(1, platform, &nplatforms);
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;
  err = clGetDeviceIDs(platform[0], CL_DEVICE_TYPE_ALL, 2, devices, &ndevices);
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;
  do {
    if (!(ndevices >= 2)) {
      fprintf(stderr,
              "Assertion: \n"
              "ndevices >= 2"
              "\nfailed on %s:%i\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/0charleschen0/pocl/refs/heads/master/"
              "tests/runtime/test_clGetSupportedImageFormats.c",
              29);
      return EXIT_FAILURE;
    }
  } while (0);
  cl_context context =
      clCreateContext(NULL, ndevices, devices, NULL, NULL, &err);
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;
  clGetSupportedImageFormats(context, 0, CL_MEM_OBJECT_IMAGE2D, 0, NULL,
                             &num_entries);
  img_formats =
      (cl_image_format *)malloc(sizeof(cl_image_format) * num_entries);
  clGetSupportedImageFormats(context, 0, CL_MEM_OBJECT_IMAGE2D, num_entries,
                             img_formats, NULL);
  if (err != CL_SUCCESS || num_entries == 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x14(%rbp),%rsi
mov    $0x1,%edi
lea    -0x18(%rbp),%rdx
call   1040 <clGetPlatformIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     11aa <main+0x4a>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
mov    -0x14(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rcx
mov    $0x2,%edx
lea    -0x24(%rbp),%r8
call   1030 <clGetDeviceIDs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2de1(%rip),%rcx
cmp    (%rcx),%rax
je     11f1 <main+0x91>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
jmp    11f6 <main+0x96>
cmpl   $0x2,-0x24(%rbp)
jge    1232 <main+0xd2>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
lea    0xe14(%rip),%rdx
mov    $0x1d,%ecx
call   1060 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
jmp    1237 <main+0xd7>
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x10(%rbp),%r9
mov    %r8,%rdi
mov    %r8,%rcx
call   1050 <clCreateContext@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
je     127a <main+0x11a>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
mov    -0x38(%rbp),%edi
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x34(%rbp),%r9
mov    %ecx,%esi
call   1070 <clGetSupportedImageFormats@plt>
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%edi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%r9d
call   1070 <clGetSupportedImageFormats@plt>
mov    -0x10(%rbp),%rax
mov    0x2ce3(%rip),%rcx
cmp    (%rcx),%rax
jne    12e8 <main+0x188>
cmpl   $0x0,-0x34(%rbp)
jne    12f9 <main+0x199>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1305 <main+0x1a5>
mov    0x2cc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x20(%rsp),%rsi
lea    0x2c(%rsp),%rdx
mov    $0x1,%edi
call   1040 <clGetPlatformIDs@plt>
mov    0x2e35(%rip),%rbx
mov    0x2e46(%rip),%rbp
cmp    (%rbx),%rax
jne    127e <main+0x11e>
mov    0x20(%rsp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0x24(%rsp),%rcx
lea    0x1c(%rsp),%r8
mov    $0x2,%edx
call   1030 <clGetDeviceIDs@plt>
mov    %rax,0x10(%rsp)
cmp    (%rbx),%rax
jne    127e <main+0x11e>
mov    0x1c(%rsp),%esi
cmp    $0x1,%esi
jle    125d <main+0xfd>
lea    0x24(%rsp),%rdx
lea    0x10(%rsp),%r9
xor    %edi,%edi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <clCreateContext@plt>
mov    %eax,%r14d
mov    0x10(%rsp),%rax
cmp    (%rbx),%rax
jne    127e <main+0x11e>
mov    0x2dcb(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xc(%rsp),%r9
mov    %r14d,%edi
xor    %esi,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <clGetSupportedImageFormats@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    0x0(%rbp),%edx
mov    0xc(%rsp),%ecx
mov    %r14d,%edi
xor    %esi,%esi
mov    %rax,%r8
xor    %r9d,%r9d
call   1070 <clGetSupportedImageFormats@plt>
mov    0x10(%rsp),%rax
cmpl   $0x0,0xc(%rsp)
mov    0x2d88(%rip),%rcx
mov    %rcx,%rbp
je     1254 <main+0xf4>
mov    0x2d6c(%rip),%rbp
cmp    (%rbx),%rax
cmovne %rcx,%rbp
jmp    127e <main+0x11e>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
lea    0xdb7(%rip),%rdx
mov    $0x1d,%ecx
call   1060 <fprintf@plt>
mov    0x0(%rbp),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Assertion: \0Andevices >= 2\0Afailed on %s:%i\0A\00"
@.str.1 = [175 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/0charleschen0/pocl/refs/heads/master/tests/runtime/test_clGetSupportedImageFormats.c\00"
@CL_MEM_OBJECT_IMAGE2D = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [1 x i32]
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%11 = call i64 @clGetPlatformIDs(i32 1, i32* %10, i32* %4)
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = load i64, i64* @CL_SUCCESS
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %1
br label %71
17: ; preds = %0
%18 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%19 = load i32, i32* %18
%20 = load i32, i32* @CL_DEVICE_TYPE_ALL
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%22 = call i64 @clGetDeviceIDs(i32 %19, i32 %20, i32 2, i32* %21, i32* %6)
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = load i64, i64* @CL_SUCCESS
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %1
br label %71
28: ; preds = %17
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = icmp sge i32 %30, 2
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.1, i64 0, i64 0), i32 29)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %1
br label %71
36: ; preds = %29
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%40 = call i32 @clCreateContext(i32* null, i32 %38, i32* %39, i32* null, i32* null, i64* %2)
store i32 %40, i32* %9
%41 = load i64, i64* %2
%42 = load i64, i64* @CL_SUCCESS
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = load i32, i32* @EXIT_FAILURE
store i32 %45, i32* %1
br label %71
46: ; preds = %37
%47 = load i32, i32* %9
%48 = load i32, i32* @CL_MEM_OBJECT_IMAGE2D
%49 = call i32 @clGetSupportedImageFormats(i32 %47, i32 0, i32 %48, i32 0, i32* null, i32* %8)
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = mul i64 4, %51
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to i32*
store i32* %55, i32** %7
%56 = load i32, i32* %9
%57 = load i32, i32* @CL_MEM_OBJECT_IMAGE2D
%58 = load i32, i32* %8
%59 = load i32*, i32** %7
%60 = call i32 @clGetSupportedImageFormats(i32 %56, i32 0, i32 %57, i32 %58, i32* %59, i32* null)
%61 = load i64, i64* %2
%62 = load i64, i64* @CL_SUCCESS
%63 = icmp ne i64 %61, %62
br i1 %63, label %67, label %64
64: ; preds = %46
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64, %46
%68 = load i32, i32* @EXIT_FAILURE
store i32 %68, i32* %1
br label %71
69: ; preds = %64
%70 = load i32, i32* @EXIT_SUCCESS
store i32 %70, i32* %1
br label %71
71: ; preds = %69, %67, %44, %32, %26, %15
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@EXIT_FAILURE = global i32 0
@CL_DEVICE_TYPE_ALL = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Assertion: \0Andevices >= 2\0Afailed on %s:%i\0A\00"
@.str.1 = [175 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/0charleschen0/pocl/refs/heads/master/tests/runtime/test_clGetSupportedImageFormats.c\00"
@CL_MEM_OBJECT_IMAGE2D = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = alloca [1 x i32]
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i64* %1 to i8*
%8 = bitcast [1 x i32]* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast [2 x i32]* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%14 = call i64 @clGetPlatformIDs(i32 1, i32* %13, i32* %3)
%15 = load i64, i64* @CL_SUCCESS
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %52
17: ; preds = %0
%18 = load i32, i32* %13
%19 = load i32, i32* @CL_DEVICE_TYPE_ALL
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%21 = call i64 @clGetDeviceIDs(i32 %18, i32 %19, i32 2, i32* %20, i32* %5)
store i64 %21, i64* %1
%22 = load i64, i64* @CL_SUCCESS
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %52
24: ; preds = %17
%25 = load i32, i32* %5
%26 = icmp sgt i32 %25, 1
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.1, i64 0, i64 0), i32 29)
br label %52
30: ; preds = %24
%31 = call i32 @clCreateContext(i32* null, i32 %25, i32* %20, i32* null, i32* null, i64* %1)
%32 = load i64, i64* %1
%33 = load i64, i64* @CL_SUCCESS
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %52
35: ; preds = %30
%36 = load i32, i32* @CL_MEM_OBJECT_IMAGE2D
%37 = call i32 @clGetSupportedImageFormats(i32 %31, i32 0, i32 %36, i32 0, i32* null, i32* %6)
%38 = load i32, i32* %6
%39 = shl i32 %38, 2
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i32*
%42 = load i32, i32* @CL_MEM_OBJECT_IMAGE2D
%43 = load i32, i32* %6
%44 = call i32 @clGetSupportedImageFormats(i32 %31, i32 0, i32 %42, i32 %43, i32* %41, i32* null)
%45 = load i64, i64* %1
%46 = load i64, i64* @CL_SUCCESS
%47 = icmp ne i64 %45, %46
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, 0
%50 = select i1 %47, i1 true, i1 %49
%51 = select i1 %50, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %52
52: ; preds = %30, %35, %17, %0, %27
%53 = phi i32* [ @EXIT_FAILURE, %27 ], [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_FAILURE, %30 ], [ %51, %35 ]
%54 = load i32, i32* %53
ret i32 %54
}