#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*/ acc_device_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ acc_device_default;
int /*<<< orphan*/ acc_free(void *);
int /*<<< orphan*/ acc_init(int /*<<< orphan*/);
void *acc_malloc(int);
int /*<<< orphan*/ acc_set_device_type(int /*<<< orphan*/);
int /*<<< orphan*/ acc_shutdown(int /*<<< orphan*/);
int main(int argc, char **argv) {
  void *d;
  acc_device_t devtype = acc_device_default;
  acc_init(devtype);
  d = acc_malloc(0);
  if (d != NULL)
    abort();
  acc_free(0);
  acc_shutdown(devtype);
  acc_set_device_type(devtype);
  d = acc_malloc(0);
  if (d != NULL)
    abort();
  acc_shutdown(devtype);
  acc_init(devtype);
  d = acc_malloc(1024);
  if (d == NULL)
    abort();
  acc_free(d);
  acc_shutdown(devtype);
  acc_set_device_type(devtype);
  d = acc_malloc(1024);
  if (d == NULL)
    abort();
  acc_free(d);
  acc_shutdown(devtype);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <acc_init@plt>
xor    %edi,%edi
call   1040 <acc_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a7 <main+0x47>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <acc_free@plt>
mov    -0x1c(%rbp),%edi
call   1050 <acc_shutdown@plt>
mov    -0x1c(%rbp),%edi
call   1070 <acc_set_device_type@plt>
xor    %edi,%edi
call   1040 <acc_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11dd <main+0x7d>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1c(%rbp),%edi
call   1050 <acc_shutdown@plt>
mov    -0x1c(%rbp),%edi
call   1080 <acc_init@plt>
mov    $0x400,%edi
call   1040 <acc_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120d <main+0xad>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rdi
call   1060 <acc_free@plt>
mov    -0x1c(%rbp),%edi
call   1050 <acc_shutdown@plt>
mov    -0x1c(%rbp),%edi
call   1070 <acc_set_device_type@plt>
mov    $0x400,%edi
call   1040 <acc_malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1246 <main+0xe6>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rdi
call   1060 <acc_free@plt>
mov    -0x1c(%rbp),%edi
call   1050 <acc_shutdown@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <acc_init@plt>
xor    %edi,%edi
call   1040 <acc_malloc@plt>
test   %rax,%rax
jne    11f3 <main+0x93>
xor    %edi,%edi
call   1060 <acc_free@plt>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
mov    %ebx,%edi
call   1070 <acc_set_device_type@plt>
xor    %edi,%edi
call   1040 <acc_malloc@plt>
test   %rax,%rax
jne    11f3 <main+0x93>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
mov    %ebx,%edi
call   1080 <acc_init@plt>
mov    $0x400,%edi
call   1040 <acc_malloc@plt>
test   %rax,%rax
je     11f3 <main+0x93>
mov    %rax,%rdi
call   1060 <acc_free@plt>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
mov    %ebx,%edi
call   1070 <acc_set_device_type@plt>
mov    $0x400,%edi
call   1040 <acc_malloc@plt>
test   %rax,%rax
je     11f3 <main+0x93>
mov    %rax,%rdi
call   1060 <acc_free@plt>
mov    %ebx,%edi
call   1050 <acc_shutdown@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@acc_device_default = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @acc_device_default
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = call i32 @acc_init(i32 %9)
%11 = call i8* @acc_malloc(i32 0)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %2
%17 = call i32 @acc_free(i8* null)
%18 = load i32, i32* %7
%19 = call i32 @acc_shutdown(i32 %18)
%20 = load i32, i32* %7
%21 = call i32 @acc_set_device_type(i32 %20)
%22 = call i8* @acc_malloc(i32 0)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %16
%28 = load i32, i32* %7
%29 = call i32 @acc_shutdown(i32 %28)
%30 = load i32, i32* %7
%31 = call i32 @acc_init(i32 %30)
%32 = call i8* @acc_malloc(i32 1024)
store i8* %32, i8** %6
%33 = load i8*, i8** %6
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %27
%38 = load i8*, i8** %6
%39 = call i32 @acc_free(i8* %38)
%40 = load i32, i32* %7
%41 = call i32 @acc_shutdown(i32 %40)
%42 = load i32, i32* %7
%43 = call i32 @acc_set_device_type(i32 %42)
%44 = call i8* @acc_malloc(i32 1024)
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = call i32 (...) @abort()
unreachable
49: ; preds = %37
%50 = load i8*, i8** %6
%51 = call i32 @acc_free(i8* %50)
%52 = load i32, i32* %7
%53 = call i32 @acc_shutdown(i32 %52)
ret i32 0
}

LLVM IR (-O2):
@acc_device_default = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @acc_device_default
%4 = tail call i32 @acc_init(i32 %3)
%5 = tail call i8* @acc_malloc(i32 0)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %2
%10 = tail call i32 @acc_free(i8* null)
%11 = tail call i32 @acc_shutdown(i32 %3)
%12 = tail call i32 @acc_set_device_type(i32 %3)
%13 = tail call i8* @acc_malloc(i32 0)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %9
%18 = tail call i32 @acc_shutdown(i32 %3)
%19 = tail call i32 @acc_init(i32 %3)
%20 = tail call i8* @acc_malloc(i32 1024)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 (...) @abort()
unreachable
24: ; preds = %17
%25 = tail call i32 @acc_free(i8* %20)
%26 = tail call i32 @acc_shutdown(i32 %3)
%27 = tail call i32 @acc_set_device_type(i32 %3)
%28 = tail call i8* @acc_malloc(i32 1024)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i32 (...) @abort()
unreachable
32: ; preds = %24
%33 = tail call i32 @acc_free(i8* %28)
%34 = tail call i32 @acc_shutdown(i32 %3)
ret i32 0
}