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

/* Variables and functions */
int /*<<< orphan*/ CL_DEVICE_TYPE_ACCELERATOR;
int /*<<< orphan*/ CL_DEVICE_TYPE_CPU;
int /*<<< orphan*/ CL_DEVICE_TYPE_GPU;
char *getenv(char *);
scalar_t__ strcasecmp(char *, char *);
cl_device_type clu_GetDefaultDeviceType() {
  char *device_type = getenv("OPENCL_DEVICE_TYPE");
  if (device_type != NULL) {
    if (strcasecmp(device_type, "cpu") == 0) {
      return CL_DEVICE_TYPE_CPU;
    } else if (strcasecmp(device_type, "gpu") == 0) {
      return CL_DEVICE_TYPE_GPU;
    } else if (strcasecmp(device_type, "accelerator") == 0) {
      return CL_DEVICE_TYPE_ACCELERATOR;
    }
  }
  return CL_DEVICE_TYPE_CPU;
}


x86 assembly (clang, -O0):
<clu_GetDefaultDeviceType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d3 <clu_GetDefaultDeviceType+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    116e <clu_GetDefaultDeviceType+0x4e>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <clu_GetDefaultDeviceType+0xbf>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1199 <clu_GetDefaultDeviceType+0x79>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <clu_GetDefaultDeviceType+0xbf>
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11c4 <clu_GetDefaultDeviceType+0xa4>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <clu_GetDefaultDeviceType+0xbf>
jmp    11c9 <clu_GetDefaultDeviceType+0xa9>
jmp    11ce <clu_GetDefaultDeviceType+0xae>
jmp    11d3 <clu_GetDefaultDeviceType+0xb3>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clu_GetDefaultDeviceType>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1171 <clu_GetDefaultDeviceType+0x51>
mov    %rax,%rbx
lea    0xed7(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1171 <clu_GetDefaultDeviceType+0x51>
lea    0xec7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     117c <clu_GetDefaultDeviceType+0x5c>
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1185 <clu_GetDefaultDeviceType+0x65>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2e65(%rip),%rax
jmp    1178 <clu_GetDefaultDeviceType+0x58>
mov    0x2e44(%rip),%rax
jmp    1178 <clu_GetDefaultDeviceType+0x58>

LLVM IR (-O0):
@.str = [19 x i8] c"OPENCL_DEVICE_TYPE\00"
@.str.1 = [4 x i8] c"cpu\00"
@CL_DEVICE_TYPE_CPU = global i32 0
@.str.2 = [4 x i8] c"gpu\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@.str.3 = [12 x i8] c"accelerator\00"
@CL_DEVICE_TYPE_ACCELERATOR = global i32 0
define i32 @clu_GetDefaultDeviceType() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %27
6: ; preds = %0
%7 = load i8*, i8** %2
%8 = call i64 @strcasecmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = load i32, i32* @CL_DEVICE_TYPE_CPU
store i32 %11, i32* %1
br label %29
12: ; preds = %6
%13 = load i8*, i8** %2
%14 = call i64 @strcasecmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @CL_DEVICE_TYPE_GPU
store i32 %17, i32* %1
br label %29
18: ; preds = %12
%19 = load i8*, i8** %2
%20 = call i64 @strcasecmp(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* @CL_DEVICE_TYPE_ACCELERATOR
store i32 %23, i32* %1
br label %29
24: ; preds = %18
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26, %0
%28 = load i32, i32* @CL_DEVICE_TYPE_CPU
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %22, %16, %10
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [19 x i8] c"OPENCL_DEVICE_TYPE\00"
@.str.1 = [4 x i8] c"cpu\00"
@CL_DEVICE_TYPE_CPU = global i32 0
@.str.2 = [4 x i8] c"gpu\00"
@CL_DEVICE_TYPE_GPU = global i32 0
@.str.3 = [12 x i8] c"accelerator\00"
@CL_DEVICE_TYPE_ACCELERATOR = global i32 0
define i32 @clu_GetDefaultDeviceType() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %12, label %3
3: ; preds = %0
%4 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @strcasecmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9, %0
br label %13
13: ; preds = %9, %6, %3, %12
%14 = phi i32* [ @CL_DEVICE_TYPE_CPU, %12 ], [ @CL_DEVICE_TYPE_CPU, %3 ], [ @CL_DEVICE_TYPE_GPU, %6 ], [ @CL_DEVICE_TYPE_ACCELERATOR, %9 ]
%15 = load i32, i32* %14
ret i32 %15
}