#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 size_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__ 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_int status = 0;
  cl_uint num_platform = 0;
  cl_platform_id *platforms = NULL;
  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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1216 <GetPlatform+0xd6>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    -0x90(%rbp),%rcx
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <clGetPlatformInfo@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e29(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x90(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1200 <GetPlatform+0xc0>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1216 <GetPlatform+0xd6>
jmp    1205 <GetPlatform+0xc5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116f <GetPlatform+0x2f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetPlatform>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
call   1030 <free@plt>
xor    %edi,%edi
cmpq   $0x0,(%rbx)
setne  %dil
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@CL_PLATFORM_VENDOR = global i32 0
@CL_SUCCESS = global i64 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
store i64 0, i64* %4
store i32** null, i32*** %5
store i64 0, i64* %6
br label %8
8: ; preds = %35, %1
%9 = load i64, i64* %6
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i32**, i32*** %5
%14 = load i64, i64* %6
%15 = getelementptr inbounds i32*, i32** %13, i64 %14
%16 = load i32*, i32** %15
%17 = load i32, i32* @CL_PLATFORM_VENDOR
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%19 = call i64 @clGetPlatformInfo(i32* %16, i32 %17, i32 100, i8* %18, i32* null)
store i64 %19, i64* %3
%20 = load i64, i64* %3
%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 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%26 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 100)
%27 = icmp ne i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %12
%29 = load i32**, i32*** %5
%30 = load i64, i64* %6
%31 = getelementptr inbounds i32*, i32** %29, i64 %30
%32 = load i32*, i32** %31
%33 = load i32**, i32*** %2
store i32* %32, i32** %33
br label %38
34: ; preds = %12
br label %35
35: ; preds = %34
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %8
38: ; preds = %28, %8
%39 = load i32**, i32*** %5
%40 = call i32 @free(i32** %39)
%41 = load i32**, i32*** %2
%42 = load i32*, i32** %41
%43 = icmp ne i32* %42, null
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
ret i32 0
}

LLVM IR (-O2):
@CL_PLATFORM_VENDOR = global i32 0
@CL_SUCCESS = global i64 0
define i32 @GetPlatform(i32** nocapture %0) {
%2 = tail call i32 @free(i32** null)
%3 = load i32*, i32** %0
%4 = icmp ne i32* %3, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
ret i32 0
}