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

/* Variables and functions */
int /*<<< orphan*/ CL_PLATFORM_VENDOR;
scalar_t__ CL_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ calloc(scalar_t__, int);
scalar_t__ clGetPlatformIDs(scalar_t__, int /*<<< orphan*/ **, scalar_t__ *);
scalar_t__ clGetPlatformInfo(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                             char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ **);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int GetPlatform(cl_platform_id *platform) {
  cl_uint num_platform = 0;
  cl_int status = clGetPlatformIDs(0, NULL, &num_platform);
  assert(status == CL_SUCCESS);
  assert(num_platform > 0);
  cl_platform_id *platforms =
      (cl_platform_id *)calloc(num_platform, sizeof(cl_platform_id));
  assert(platforms);
  status = clGetPlatformIDs(num_platform, platforms, NULL);
  assert(status == CL_SUCCESS);
  assert(platforms);
  for (cl_uint i = 0; i < num_platform; ++i) {
    char buf[100];
    printf("\nPlatform %d\n", i);
    status = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(buf),
                               buf, NULL);
    assert(status == CL_SUCCESS);
    printf("CL_PLATFORM_VENDOR: %s\n", buf);
    if (!strncmp(buf, "Advanced Micro Devices, Inc.", 100)) {
      *platform = platforms[i];
      break;
    }
  }
  free(platforms);
  assert(*platform != NULL);
  return 0;
}


x86 assembly (clang, -O0):
<GetPlatform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
mov    %rsi,%rdi
call   1050 <clGetPlatformIDs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1090 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <clGetPlatformIDs@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2ddb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1090 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    12f2 <GetPlatform+0x182>
mov    -0x28(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
lea    -0x90(%rbp),%rcx
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1070 <clGetPlatformInfo@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d60(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
lea    -0x90(%rbp),%rsi
lea    0xd70(%rip),%rdi
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12dc <GetPlatform+0x16c>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    12f2 <GetPlatform+0x182>
jmp    12e1 <GetPlatform+0x171>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1228 <GetPlatform+0xb8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1090 <assert@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPlatform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1050 <clGetPlatformIDs@plt>
mov    0x2e42(%rip),%rbx
xor    %edi,%edi
cmp    (%rbx),%rax
sete   %dil
call   1090 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setg   %dil
call   1090 <assert@plt>
mov    (%rsp),%rdi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    %r15d,%edi
call   1090 <assert@plt>
mov    (%rsp),%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <clGetPlatformIDs@plt>
xor    %edi,%edi
cmp    (%rbx),%rax
sete   %dil
call   1090 <assert@plt>
mov    %r15d,%edi
call   1090 <assert@plt>
cmpq   $0x0,(%rsp)
jle    1293 <GetPlatform+0x123>
xor    %ebx,%ebx
mov    0x2dc3(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xdf5(%rip),%rbp
lea    0xe06(%rip),%r14
lea    0xdd9(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    (%r15,%rbx,8),%rdi
mov    (%r12),%esi
mov    $0x64,%edx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1070 <clGetPlatformInfo@plt>
xor    %edi,%edi
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%rax
sete   %dil
call   1090 <assert@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1287 <GetPlatform+0x117>
add    $0x1,%rbx
cmp    (%rsp),%rbx
jl     1220 <GetPlatform+0xb0>
jmp    1293 <GetPlatform+0x123>
mov    (%r15,%rbx,8),%rax
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
mov    0x8(%rsp),%rax
cmpq   $0x0,(%rax)
setne  %dil
call   1090 <assert@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_SUCCESS = global i64 0
@.str = [14 x i8] c"\0APlatform %d\0A\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.1 = [24 x i8] c"CL_PLATFORM_VENDOR: %s\0A\00"
@.str.2 = [29 x i8] c"Advanced Micro Devices, Inc.\00"
define i32 @GetPlatform(i32** %0) {
%2 = alloca i32**
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32**
%6 = alloca i64
%7 = alloca [100 x i8]
store i32** %0, i32*** %2
store i64 0, i64* %3
%8 = call i64 @clGetPlatformIDs(i64 0, i32** null, i64* %3)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = load i64, i64* @CL_SUCCESS
%11 = icmp eq i64 %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %3
%15 = icmp sgt i64 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %3
%19 = call i64 @calloc(i64 %18, i32 8)
%20 = inttoptr i64 %19 to i32**
store i32** %20, i32*** %5
%21 = load i32**, i32*** %5
%22 = ptrtoint i32** %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i64, i64* %3
%25 = load i32**, i32*** %5
%26 = call i64 @clGetPlatformIDs(i64 %24, i32** %25, i64* null)
store i64 %26, i64* %4
%27 = load i64, i64* %4
%28 = load i64, i64* @CL_SUCCESS
%29 = icmp eq i64 %27, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32**, i32*** %5
%33 = ptrtoint i32** %32 to i32
%34 = call i32 @assert(i32 %33)
store i64 0, i64* %6
br label %35
35: ; preds = %67, %1
%36 = load i64, i64* %6
%37 = load i64, i64* %3
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %70
39: ; preds = %35
%40 = load i64, i64* %6
%41 = inttoptr i64 %40 to i8*
%42 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = load i32**, i32*** %5
%44 = load i64, i64* %6
%45 = getelementptr inbounds i32*, i32** %43, i64 %44
%46 = load i32*, i32** %45
%47 = load i32, i32* @CL_PLATFORM_VENDOR
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%49 = call i64 @clGetPlatformInfo(i32* %46, i32 %47, i32 100, i8* %48, i32* null)
store i64 %49, i64* %4
%50 = load i64, i64* %4
%51 = load i64, i64* @CL_SUCCESS
%52 = icmp eq i64 %50, %51
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%56 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%58 = call i32 @strncmp(i8* %57, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 100)
%59 = icmp ne i32 %58, 0
br i1 %59, label %66, label %60
60: ; preds = %39
%61 = load i32**, i32*** %5
%62 = load i64, i64* %6
%63 = getelementptr inbounds i32*, i32** %61, i64 %62
%64 = load i32*, i32** %63
%65 = load i32**, i32*** %2
store i32* %64, i32** %65
br label %70
66: ; preds = %39
br label %67
67: ; preds = %66
%68 = load i64, i64* %6
%69 = add nsw i64 %68, 1
store i64 %69, i64* %6
br label %35
70: ; preds = %60, %35
%71 = load i32**, i32*** %5
%72 = call i32 @free(i32** %71)
%73 = load i32**, i32*** %2
%74 = load i32*, i32** %73
%75 = icmp ne i32* %74, null
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
ret i32 0
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@.str = [14 x i8] c"\0APlatform %d\0A\00"
@CL_PLATFORM_VENDOR = global i32 0
@.str.1 = [24 x i8] c"CL_PLATFORM_VENDOR: %s\0A\00"
@.str.2 = [29 x i8] c"Advanced Micro Devices, Inc.\00"
define i32 @GetPlatform(i32** nocapture %0) {
%2 = alloca i64
%3 = alloca [100 x i8]
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = call i64 @clGetPlatformIDs(i64 0, i32** null, i64* %2)
%6 = load i64, i64* @CL_SUCCESS
%7 = icmp eq i64 %5, %6
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* %2
%11 = icmp sgt i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %2
%15 = call i64 @calloc(i64 %14, i32 8)
%16 = inttoptr i64 %15 to i32**
%17 = trunc i64 %15 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %2
%20 = call i64 @clGetPlatformIDs(i64 %19, i32** %16, i64* null)
%21 = load i64, i64* @CL_SUCCESS
%22 = icmp eq i64 %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @assert(i32 %17)
%26 = load i64, i64* %2
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %1
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %30
30: ; preds = %28, %48
%31 = phi i64 [ 0, %28 ], [ %49, %48 ]
%32 = inttoptr i64 %31 to i8*
%33 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds i32*, i32** %16, i64 %31
%35 = load i32*, i32** %34
%36 = load i32, i32* @CL_PLATFORM_VENDOR
%37 = call i64 @clGetPlatformInfo(i32* %35, i32 %36, i32 100, i8* %29, i32* null)
%38 = load i64, i64* @CL_SUCCESS
%39 = icmp eq i64 %37, %38
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%43 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 100)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %30
%46 = getelementptr inbounds i32*, i32** %16, i64 %31
%47 = load i32*, i32** %46
store i32* %47, i32** %0
br label %52
48: ; preds = %30
%49 = add nuw nsw i64 %31, 1
%50 = load i64, i64* %2
%51 = icmp slt i64 %49, %50
br i1 %51, label %30, label %52
52: ; preds = %48, %1, %45
%53 = call i32 @free(i32** %16)
%54 = load i32*, i32** %0
%55 = icmp ne i32* %54, null
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
ret i32 0
}