#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*/ pbuf;
typedef int /*<<< orphan*/ devType;
typedef int /*<<< orphan*/ cl_int;
typedef int cl_device_type;
typedef int /*<<< orphan*/ cl_device_id;

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_NAME;
int /*<<< orphan*/ CL_DEVICE_TYPE;
#define CL_DEVICE_TYPE_CPU 129
#define CL_DEVICE_TYPE_GPU 128
int /*<<< orphan*/ CL_SUCCESS;
int /*<<< orphan*/ checkErr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ clGetDeviceInfo(int /*<<< orphan*/, int /*<<< orphan*/, int,
                                   ...);
int /*<<< orphan*/ printf(char *, ...);
void printDeviceName(size_t dev_id, cl_device_id device) {
  int i = 0;
  cl_int err = CL_SUCCESS;
  cl_device_type devType;
  char pbuf[100];
  printf("DEVICE[%d]: ", dev_id);
  err =
      clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(devType), &devType, NULL);
  checkErr("clGetDeviceInfo", err);
  switch (devType) {
  case CL_DEVICE_TYPE_CPU:
    printf("CL_DEVICE_TYPE_CPU, ");
    break;
  case CL_DEVICE_TYPE_GPU:
    printf("CL_DEVICE_TYPE_GPU, ");
    break;
  default:
    printf("Unknown device type %d, ", devType);
    break;
  }
  err = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(pbuf), pbuf, NULL);
  checkErr("clGetDeviceINfo", err);
  printf("Name=%s\n", pbuf);
}


x86 assembly (clang, -O0):
<printDeviceName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea0(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x8c(%rbp)
mov    %al,-0x85(%rbp)
call   1040 <printf@plt>
mov    -0x8c(%rbp),%ecx
mov    -0x85(%rbp),%al
mov    -0xc(%rbp),%edi
mov    0x2e3f(%rip),%rdx
mov    (%rdx),%esi
mov    %ecx,%r8d
mov    $0x4,%edx
lea    -0x18(%rbp),%rcx
call   1030 <clGetDeviceInfo@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe64(%rip),%rdi
call   1050 <checkErr@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x84(%rbp)
sub    $0x80,%eax
je     11f0 <printDeviceName+0xc0>
jmp    11c7 <printDeviceName+0x97>
mov    -0x84(%rbp),%eax
sub    $0x81,%eax
jne    1203 <printDeviceName+0xd3>
jmp    11dd <printDeviceName+0xad>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1214 <printDeviceName+0xe4>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1214 <printDeviceName+0xe4>
mov    -0x18(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    -0x80(%rbp),%rcx
mov    $0x64,%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1030 <clGetDeviceInfo@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1050 <checkErr@plt>
lea    -0x80(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDeviceName>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    %esi,%ebp
mov    %rdi,%rsi
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%edx
xor    %r8d,%r8d
xor    %eax,%eax
call   1030 <clGetDeviceInfo@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1050 <checkErr@plt>
mov    0xc(%rsp),%esi
cmp    $0x80,%esi
je     1193 <printDeviceName+0x63>
cmp    $0x81,%esi
jne    11a3 <printDeviceName+0x73>
lea    0xe8c(%rip),%rdi
jmp    119a <printDeviceName+0x6a>
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b1 <printDeviceName+0x81>
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    $0x64,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1030 <clGetDeviceInfo@plt>
lea    0xe86(%rip),%rdi
mov    %eax,%esi
call   1050 <checkErr@plt>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CL_SUCCESS = global i32 0
@.str = [13 x i8] c"DEVICE[%d]: \00"
@CL_DEVICE_TYPE = global i32 0
@.str.1 = [16 x i8] c"clGetDeviceInfo\00"
@.str.2 = [21 x i8] c"CL_DEVICE_TYPE_CPU, \00"
@.str.3 = [21 x i8] c"CL_DEVICE_TYPE_GPU, \00"
@.str.4 = [25 x i8] c"Unknown device type %d, \00"
@CL_DEVICE_NAME = global i32 0
@.str.5 = [16 x i8] c"clGetDeviceINfo\00"
@.str.6 = [9 x i8] c"Name=%s\0A\00"
define void @printDeviceName(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i64 %0, i64* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* @CL_SUCCESS
store i32 %9, i32* %6
%10 = load i64, i64* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* %4
%13 = load i32, i32* @CL_DEVICE_TYPE
%14 = call i32 (i32, i32, i32, ...) @clGetDeviceInfo(i32 %12, i32 %13, i32 4, i32* %7, i8* null)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %7
switch i32 %17, label %22 [
i32 129, label %18
i32 128, label %20
]
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %25
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %25
22: ; preds = %2
%23 = load i32, i32* %7
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %20, %18
%26 = load i32, i32* %4
%27 = load i32, i32* @CL_DEVICE_NAME
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%29 = call i32 (i32, i32, i32, ...) @clGetDeviceInfo(i32 %26, i32 %27, i32 100, i8* %28, i8* null)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %32)
ret void
}

LLVM IR (-O2):
@CL_SUCCESS = global i32 0
@.str = [13 x i8] c"DEVICE[%d]: \00"
@CL_DEVICE_TYPE = global i32 0
@.str.1 = [16 x i8] c"clGetDeviceInfo\00"
@.str.2 = [21 x i8] c"CL_DEVICE_TYPE_CPU, \00"
@.str.3 = [21 x i8] c"CL_DEVICE_TYPE_GPU, \00"
@.str.4 = [25 x i8] c"Unknown device type %d, \00"
@CL_DEVICE_NAME = global i32 0
@.str.5 = [16 x i8] c"clGetDeviceINfo\00"
@.str.6 = [9 x i8] c"Name=%s\0A\00"
define void @printDeviceName(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %0)
%8 = load i32, i32* @CL_DEVICE_TYPE
%9 = call i32 (i32, i32, i32, ...) @clGetDeviceInfo(i32 %1, i32 %8, i32 4, i32* %3, i8* null)
%10 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
switch i32 %11, label %16 [
i32 129, label %12
i32 128, label %14
]
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %18
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %18
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %11)
br label %18
18: ; preds = %16, %14, %12
%19 = load i32, i32* @CL_DEVICE_NAME
%20 = call i32 (i32, i32, i32, ...) @clGetDeviceInfo(i32 %1, i32 %19, i32 100, i8* %6, i8* null)
%21 = call i32 @checkErr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %6)
ret void
}