#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;

/* Variables and functions */
scalar_t__ CL_PLATFORM_NOT_FOUND_KHR;
scalar_t__ CL_SUCCESS;
scalar_t__ clGetPlatformIDs(int, int /*<<< orphan*/ **, int *);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_error(scalar_t__);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ show_platform(int /*<<< orphan*/ *, int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  cl_platform_id *platforms;
  cl_uint num_platforms;
  cl_int error;
  int show_extensions = 0;
  if (argc >= 2 && strcmp(argv[1], "--show-extensions") == 0) {
    show_extensions = 1;
    argv++;
  }
  int default_platform = 0;
  if (argc >= 2 && strcmp(argv[1], "--default-platform") == 0) {
    default_platform = 1;
  }
  error = clGetPlatformIDs(0, NULL, &num_platforms);
  if (error == CL_SUCCESS) {
    printf("Found %u platforms!\n", num_platforms);
  } else if (error == CL_PLATFORM_NOT_FOUND_KHR) {
    print_error(error);
    if (default_platform) {
      show_platform(NULL, show_extensions);
    }
    exit(0);
  } else {
    print_error(error);
    exit(-1);
  }
  platforms =
      (cl_platform_id *)malloc(sizeof(cl_platform_id *) * num_platforms);
  error = clGetPlatformIDs(num_platforms, platforms, NULL);
  print_error(error);
  cl_uint i;
  for (i = 0; i < num_platforms; i++) {
    show_platform(platforms[i], show_extensions);
  }
  if (default_platform) {
    show_platform(NULL, show_extensions);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11c8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11c8 <main+0x58>
movl   $0x1,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11fe <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11fe <main+0x8e>
movl   $0x1,-0x30(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x1c(%rbp),%rdx
call   1040 <clGetPlatformIDs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2dbc(%rip),%rcx
cmp    (%rcx),%rax
jne    1239 <main+0xc9>
mov    -0x1c(%rbp),%esi
lea    0xdf6(%rip),%rdi
call   1050 <printf@plt>
jmp    1286 <main+0x116>
mov    -0x28(%rbp),%rax
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%rax
jne    1273 <main+0x103>
mov    -0x28(%rbp),%rdi
call   1030 <print_error@plt>
cmpl   $0x0,-0x30(%rbp)
je     126c <main+0xfc>
mov    -0x2c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <show_platform@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <print_error@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <clGetPlatformIDs@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <print_error@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12eb <main+0x17b>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x2c(%rbp),%esi
call   1080 <show_platform@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12bd <main+0x14d>
cmpl   $0x0,-0x30(%rbp)
je     1301 <main+0x191>
mov    -0x2c(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <show_platform@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11ba <main+0x4a>
mov    %rsi,%rbx
lea    0x8(%rsi),%rbp
mov    0x8(%rsi),%rdi
lea    0xe72(%rip),%rsi
call   1060 <strcmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
sete   %r15b
cmovne %rbx,%rbp
mov    0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
setne  %r14b
jmp    11c0 <main+0x50>
mov    $0x1,%r14b
xor    %r15d,%r15d
lea    0x4(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1040 <clGetPlatformIDs@plt>
mov    %rax,%rbx
mov    0x2e00(%rip),%rax
cmp    (%rax),%rbx
jne    1256 <main+0xe6>
mov    0x4(%rsp),%esi
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%edi
mov    %rax,%rsi
xor    %edx,%edx
call   1040 <clGetPlatformIDs@plt>
mov    %rax,%rdi
call   1030 <print_error@plt>
cmpl   $0x0,0x4(%rsp)
jle    123a <main+0xca>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdi
mov    %r15d,%esi
call   1080 <show_platform@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
cmp    %rax,%rbp
jl     1220 <main+0xb0>
test   %r14b,%r14b
jne    1249 <main+0xd9>
xor    %edi,%edi
mov    %r15d,%esi
call   1080 <show_platform@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d83(%rip),%rax
mov    (%rax),%rbp
mov    %rbx,%rdi
call   1030 <print_error@plt>
cmp    %rbp,%rbx
jne    1283 <main+0x113>
test   %r14b,%r14b
jne    127c <main+0x10c>
xor    %edi,%edi
mov    %r15d,%esi
call   1080 <show_platform@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"--show-extensions\00"
@.str.1 = [19 x i8] c"--default-platform\00"
@CL_SUCCESS = global i64 0
@.str.2 = [21 x i8] c"Found %u platforms!\0A\00"
@CL_PLATFORM_NOT_FOUND_KHR = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 2
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
store i32 1, i32* %9
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i32 1
store i8** %22, i8*** %5
br label %23
23: ; preds = %20, %14, %2
store i32 0, i32* %10
%24 = load i32, i32* %4
%25 = icmp sge i32 %24, 2
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %10
br label %33
33: ; preds = %32, %26, %23
%34 = call i64 @clGetPlatformIDs(i32 0, i32** null, i32* %7)
store i64 %34, i64* %8
%35 = load i64, i64* %8
%36 = load i64, i64* @CL_SUCCESS
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %7
%40 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %59
41: ; preds = %33
%42 = load i64, i64* %8
%43 = load i64, i64* @CL_PLATFORM_NOT_FOUND_KHR
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i64, i64* %8
%47 = call i32 @print_error(i64 %46)
%48 = load i32, i32* %10
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = load i32, i32* %9
%52 = call i32 @show_platform(i32* null, i32 %51)
br label %53
53: ; preds = %50, %45
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %41
%56 = load i64, i64* %8
%57 = call i32 @print_error(i64 %56)
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %38
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = mul i64 8, %61
%63 = trunc i64 %62 to i32
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i32**
store i32** %65, i32*** %6
%66 = load i32, i32* %7
%67 = load i32**, i32*** %6
%68 = call i64 @clGetPlatformIDs(i32 %66, i32** %67, i32* null)
store i64 %68, i64* %8
%69 = load i64, i64* %8
%70 = call i32 @print_error(i64 %69)
store i32 0, i32* %11
br label %71
71: ; preds = %83, %59
%72 = load i32, i32* %11
%73 = load i32, i32* %7
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %86
75: ; preds = %71
%76 = load i32**, i32*** %6
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32*, i32** %76, i64 %78
%80 = load i32*, i32** %79
%81 = load i32, i32* %9
%82 = call i32 @show_platform(i32* %80, i32 %81)
br label %83
83: ; preds = %75
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %71
86: ; preds = %71
%87 = load i32, i32* %10
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* %9
%91 = call i32 @show_platform(i32* null, i32 %90)
br label %92
92: ; preds = %89, %86
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"--show-extensions\00"
@.str.1 = [19 x i8] c"--default-platform\00"
@CL_SUCCESS = global i64 0
@.str.2 = [21 x i8] c"Found %u platforms!\0A\00"
@CL_PLATFORM_NOT_FOUND_KHR = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8** %7, i8** %1
%12 = zext i1 %10 to i32
%13 = getelementptr inbounds i8*, i8** %11, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %2, %6
%18 = phi i32 [ %12, %6 ], [ 0, %2 ]
%19 = phi i1 [ %16, %6 ], [ true, %2 ]
%20 = call i64 @clGetPlatformIDs(i32 0, i32** null, i32* %3)
%21 = load i64, i64* @CL_SUCCESS
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %17
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = shl i32 %26, 3
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32**
%30 = load i32, i32* %3
%31 = call i64 @clGetPlatformIDs(i32 %30, i32** %29, i32* null)
%32 = call i32 @print_error(i64 %31)
%33 = load i32, i32* %3
%34 = icmp sgt i32 %33, 0
br i1 %34, label %46, label %55
35: ; preds = %17
%36 = load i64, i64* @CL_PLATFORM_NOT_FOUND_KHR
%37 = icmp eq i64 %20, %36
%38 = call i32 @print_error(i64 %20)
br i1 %37, label %39, label %44
39: ; preds = %35
br i1 %19, label %42, label %40
40: ; preds = %39
%41 = call i32 @show_platform(i32* null, i32 %18)
br label %42
42: ; preds = %40, %39
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %35
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %23, %46
%47 = phi i64 [ %51, %46 ], [ 0, %23 ]
%48 = getelementptr inbounds i32*, i32** %29, i64 %47
%49 = load i32*, i32** %48
%50 = call i32 @show_platform(i32* %49, i32 %18)
%51 = add nuw nsw i64 %47, 1
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %46, label %55
55: ; preds = %46, %23
br i1 %19, label %58, label %56
56: ; preds = %55
%57 = call i32 @show_platform(i32* null, i32 %18)
br label %58
58: ; preds = %56, %55
ret i32 0
}