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

/* 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*/ 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];
    status = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof buf,
                               buf, NULL);
    assert(status == CL_SUCCESS);
    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    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1080 <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    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1080 <assert@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    12bf <GetPlatform+0x15f>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
lea    -0x90(%rbp),%rcx
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <clGetPlatformInfo@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x90(%rbp),%rdi
lea    0xd82(%rip),%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12a9 <GetPlatform+0x149>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    12bf <GetPlatform+0x15f>
jmp    12ae <GetPlatform+0x14e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1218 <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   1080 <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    0x2e52(%rip),%r13
xor    %edi,%edi
cmp    0x0(%r13),%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setg   %dil
call   1080 <assert@plt>
mov    (%rsp),%rdi
mov    $0x8,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
mov    %r15d,%edi
call   1080 <assert@plt>
mov    (%rsp),%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <clGetPlatformIDs@plt>
xor    %edi,%edi
cmp    0x0(%r13),%rax
sete   %dil
call   1080 <assert@plt>
mov    %r15d,%edi
call   1080 <assert@plt>
cmpq   $0x0,(%rsp)
jle    1262 <GetPlatform+0x102>
xor    %ebp,%ebp
mov    0x2dd5(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xdf9(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rdi
mov    (%r14),%esi
mov    $0x64,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1060 <clGetPlatformInfo@plt>
xor    %edi,%edi
cmp    0x0(%r13),%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1256 <GetPlatform+0xf6>
add    $0x1,%rbp
cmp    (%rsp),%rbp
jl     1210 <GetPlatform+0xb0>
jmp    1262 <GetPlatform+0x102>
mov    (%r15,%rbp,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   1080 <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
@CL_PLATFORM_VENDOR = global i32 0
@.str = [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 = %62, %1
%36 = load i64, i64* %6
%37 = load i64, i64* %3
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %65
39: ; preds = %35
%40 = load i32**, i32*** %5
%41 = load i64, i64* %6
%42 = getelementptr inbounds i32*, i32** %40, i64 %41
%43 = load i32*, i32** %42
%44 = load i32, i32* @CL_PLATFORM_VENDOR
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%46 = call i64 @clGetPlatformInfo(i32* %43, i32 %44, i32 100, i8* %45, i32* null)
store i64 %46, i64* %4
%47 = load i64, i64* %4
%48 = load i64, i64* @CL_SUCCESS
%49 = icmp eq i64 %47, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%53 = call i32 @strncmp(i8* %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 100)
%54 = icmp ne i32 %53, 0
br i1 %54, label %61, label %55
55: ; preds = %39
%56 = load i32**, i32*** %5
%57 = load i64, i64* %6
%58 = getelementptr inbounds i32*, i32** %56, i64 %57
%59 = load i32*, i32** %58
%60 = load i32**, i32*** %2
store i32* %59, i32** %60
br label %65
61: ; preds = %39
br label %62
62: ; preds = %61
%63 = load i64, i64* %6
%64 = add nsw i64 %63, 1
store i64 %64, i64* %6
br label %35
65: ; preds = %55, %35
%66 = load i32**, i32*** %5
%67 = call i32 @free(i32** %66)
%68 = load i32**, i32*** %2
%69 = load i32*, i32** %68
%70 = icmp ne i32* %69, null
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
ret i32 0
}

LLVM IR (-O2):
@CL_SUCCESS = global i64 0
@CL_PLATFORM_VENDOR = global i32 0
@.str = [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 %49
28: ; preds = %1
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %30
30: ; preds = %28, %45
%31 = phi i64 [ 0, %28 ], [ %46, %45 ]
%32 = getelementptr inbounds i32*, i32** %16, i64 %31
%33 = load i32*, i32** %32
%34 = load i32, i32* @CL_PLATFORM_VENDOR
%35 = call i64 @clGetPlatformInfo(i32* %33, i32 %34, i32 100, i8* %29, i32* null)
%36 = load i64, i64* @CL_SUCCESS
%37 = icmp eq i64 %35, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 100)
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %30
%43 = getelementptr inbounds i32*, i32** %16, i64 %31
%44 = load i32*, i32** %43
store i32* %44, i32** %0
br label %49
45: ; preds = %30
%46 = add nuw nsw i64 %31, 1
%47 = load i64, i64* %2
%48 = icmp slt i64 %46, %47
br i1 %48, label %30, label %49
49: ; preds = %45, %1, %42
%50 = call i32 @free(i32** %16)
%51 = load i32*, i32** %0
%52 = icmp ne i32* %51, null
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
ret i32 0
}