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

/* Variables and functions */
int /*<<< orphan*/ CL_PLATFORM_EXTENSIONS;
int /*<<< orphan*/ CL_PLATFORM_VENDOR;
scalar_t__ CL_SUCCESS;
scalar_t__ clGetPlatformInfo(int /*<<< orphan*/, int /*<<< orphan*/, size_t,
                             char *, size_t *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ print_error(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
void show_platform(cl_platform_id pid, int show_extensions) {
  char *platform_vendor;
  size_t param_value_size_ret;
  cl_int error;
  error = clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, 0, NULL,
                            &param_value_size_ret);
  print_error(error);
  if (error != CL_SUCCESS)
    return;
  platform_vendor = (char *)malloc(param_value_size_ret);
  clGetPlatformInfo(pid, CL_PLATFORM_VENDOR, param_value_size_ret,
                    platform_vendor, NULL);
  printf("%s\n", platform_vendor);
  free(platform_vendor);
  if (show_extensions) {
    error = clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, 0, NULL,
                              &param_value_size_ret);
    print_error(error);
    platform_vendor = (char *)malloc(param_value_size_ret);
    clGetPlatformInfo(pid, CL_PLATFORM_EXTENSIONS, param_value_size_ret,
                      platform_vendor, NULL);
    printf("Extensions: %s\n", platform_vendor);
    free(platform_vendor);
  }
}


x86 assembly (clang, -O0):
<show_platform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1060 <clGetPlatformInfo@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <print_error@plt>
mov    -0x20(%rbp),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
je     11a0 <show_platform+0x50>
jmp    125b <show_platform+0x10b>
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <clGetPlatformInfo@plt>
mov    -0x10(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x8(%rbp)
je     125b <show_platform+0x10b>
mov    -0x4(%rbp),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1060 <clGetPlatformInfo@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <print_error@plt>
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <clGetPlatformInfo@plt>
mov    -0x10(%rbp),%rsi
lea    0xdb3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_platform>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
mov    0x2e6d(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <clGetPlatformInfo@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <print_error@plt>
mov    0x2e5c(%rip),%rax
cmp    (%rax),%rbp
jne    1220 <show_platform+0xd0>
mov    (%rsp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    (%r15),%esi
mov    (%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %r8d,%r8d
call   1060 <clGetPlatformInfo@plt>
lea    0xe58(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
je     1220 <show_platform+0xd0>
mov    0x2df8(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%r8
mov    %ebx,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <clGetPlatformInfo@plt>
mov    %rax,%rdi
call   1040 <print_error@plt>
mov    (%rsp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    (%r14),%esi
mov    (%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %r8d,%r8d
call   1060 <clGetPlatformInfo@plt>
lea    0xdf0(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CL_PLATFORM_VENDOR = global i32 0
@CL_SUCCESS = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@CL_PLATFORM_EXTENSIONS = global i32 0
@.str.1 = [16 x i8] c"Extensions: %s\0A\00"
define void @show_platform(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = load i32, i32* @CL_PLATFORM_VENDOR
%10 = call i64 @clGetPlatformInfo(i32 %8, i32 %9, i64 0, i8* null, i64* %6)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = call i32 @print_error(i64 %11)
%13 = load i64, i64* %7
%14 = load i64, i64* @CL_SUCCESS
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %2
br label %50
17: ; preds = %2
%18 = load i64, i64* %6
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %5
%21 = load i32, i32* %3
%22 = load i32, i32* @CL_PLATFORM_VENDOR
%23 = load i64, i64* %6
%24 = load i8*, i8** %5
%25 = call i64 @clGetPlatformInfo(i32 %21, i32 %22, i64 %23, i8* %24, i64* null)
%26 = load i8*, i8** %5
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %50
32: ; preds = %17
%33 = load i32, i32* %3
%34 = load i32, i32* @CL_PLATFORM_EXTENSIONS
%35 = call i64 @clGetPlatformInfo(i32 %33, i32 %34, i64 0, i8* null, i64* %6)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = call i32 @print_error(i64 %36)
%38 = load i64, i64* %6
%39 = call i64 @malloc(i64 %38)
%40 = inttoptr i64 %39 to i8*
store i8* %40, i8** %5
%41 = load i32, i32* %3
%42 = load i32, i32* @CL_PLATFORM_EXTENSIONS
%43 = load i64, i64* %6
%44 = load i8*, i8** %5
%45 = call i64 @clGetPlatformInfo(i32 %41, i32 %42, i64 %43, i8* %44, i64* null)
%46 = load i8*, i8** %5
%47 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i8*, i8** %5
%49 = call i32 @free(i8* %48)
br label %50
50: ; preds = %16, %32, %17
ret void
}

LLVM IR (-O2):
@CL_PLATFORM_VENDOR = global i32 0
@CL_SUCCESS = global i64 0
@.str = [4 x i8] c"%s\0A\00"
@CL_PLATFORM_EXTENSIONS = global i32 0
@.str.1 = [16 x i8] c"Extensions: %s\0A\00"
define void @show_platform(i32 %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i32, i32* @CL_PLATFORM_VENDOR
%6 = call i64 @clGetPlatformInfo(i32 %0, i32 %5, i64 0, i8* null, i64* %3)
%7 = call i32 @print_error(i64 %6)
%8 = load i64, i64* @CL_SUCCESS
%9 = icmp eq i64 %6, %8
br i1 %9, label %10, label %32
10: ; preds = %2
%11 = load i64, i64* %3
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = load i32, i32* @CL_PLATFORM_VENDOR
%15 = load i64, i64* %3
%16 = call i64 @clGetPlatformInfo(i32 %0, i32 %14, i64 %15, i8* %13, i64* null)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%18 = call i32 @free(i8* %13)
%19 = icmp eq i32 %1, 0
br i1 %19, label %32, label %20
20: ; preds = %10
%21 = load i32, i32* @CL_PLATFORM_EXTENSIONS
%22 = call i64 @clGetPlatformInfo(i32 %0, i32 %21, i64 0, i8* null, i64* %3)
%23 = call i32 @print_error(i64 %22)
%24 = load i64, i64* %3
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
%27 = load i32, i32* @CL_PLATFORM_EXTENSIONS
%28 = load i64, i64* %3
%29 = call i64 @clGetPlatformInfo(i32 %0, i32 %27, i64 %28, i8* %26, i64* null)
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%31 = call i32 @free(i8* %26)
br label %32
32: ; preds = %10, %20, %2
ret void
}