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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int ioctl(int, int, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int dump_check_zcore(void) {
  int rc = 0;
  int error_code;
  int fh;
  fh = open("/dev/zcore", O_RDWR);
  if (fh == -1) {
    {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "open %s failed\n", "/dev/zcore");
      perror("");
    };
    rc = -1;
    goto out;
  }
  if (ioctl(fh, 0x3, &error_code) == -1) {
    {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "ioctl 'get error code' failed\n");
      perror("");
    };
    rc = -1;
    goto out;
  }
  switch (error_code) {
  case 0x0:
    break;
  case 0x1: {
    fprintf(stderr, "ERROR: ");
    fprintf(stderr, "HSA - Feature not working\n");
  };
    rc = -1;
    goto out;
  case 0x2: {
    fprintf(stderr, "ERROR: ");
    fprintf(stderr, "HSA - NO CPU INFO\n");
  };
    rc = -1;
    goto out;
  case 0x3:
  default: {
    fprintf(stderr, "ERROR: ");
    fprintf(stderr, "HSA - ERROR\n");
  };
    rc = -1;
    goto out;
  }
out:
  if (fh != -1)
    close(fh);
  return rc;
}


x86 assembly (clang, -O0):
<dump_check_zcore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ce <dump_check_zcore+0x7e>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
lea    0xe61(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xec2(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <dump_check_zcore+0x1c0>
mov    -0xc(%rbp),%edi
mov    $0x3,%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    122e <dump_check_zcore+0xde>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xe62(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <dump_check_zcore+0x1c0>
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     12d1 <dump_check_zcore+0x181>
mov    -0x18(%rbp),%rax
lea    0xdb6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    130b <dump_check_zcore+0x1bb>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <dump_check_zcore+0x1c0>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <dump_check_zcore+0x1c0>
jmp    12d1 <dump_check_zcore+0x181>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd3a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <dump_check_zcore+0x1c0>
jmp    1310 <dump_check_zcore+0x1c0>
cmpl   $0xffffffff,-0xc(%rbp)
je     1322 <dump_check_zcore+0x1d2>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_check_zcore>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1229 <dump_check_zcore+0xd9>
mov    %eax,%ebx
lea    0x4(%rsp),%rdx
mov    %eax,%edi
mov    $0x3,%esi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     126a <dump_check_zcore+0x11a>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
je     1219 <dump_check_zcore+0xc9>
cmp    $0x2,%ebp
je     11c7 <dump_check_zcore+0x77>
cmp    $0x1,%ebp
jne    11eb <dump_check_zcore+0x9b>
mov    0x2e2e(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe7d(%rip),%rsi
jmp    120d <dump_check_zcore+0xbd>
mov    0x2e0a(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe74(%rip),%rsi
jmp    120d <dump_check_zcore+0xbd>
mov    0x2de6(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe63(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2da8(%rip),%rbx
mov    (%rbx),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdca(%rip),%rsi
lea    0xdb0(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1220 <dump_check_zcore+0xd0>
mov    0x2d67(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd90(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdd5(%rip),%rdi
call   1070 <perror@plt>
jmp    1214 <dump_check_zcore+0xc4>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/zcore\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [16 x i8] c"open %s failed\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [31 x i8] c"ioctl 'get error code' failed\0A\00"
@.str.5 = [27 x i8] c"HSA - Feature not working\0A\00"
@.str.6 = [19 x i8] c"HSA - NO CPU INFO\0A\00"
@.str.7 = [13 x i8] c"HSA - ERROR\0A\00"
define i32 @dump_check_zcore() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
14: ; preds = %0
%15 = load i32, i32* %3
%16 = call i32 @ioctl(i32 %15, i32 3, i32* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
24: ; preds = %14
%25 = load i32, i32* %2
switch i32 %25, label %38 [
i32 0, label %26
i32 1, label %27
i32 2, label %32
i32 3, label %37
]
26: ; preds = %24
br label %43
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
37: ; preds = %24
br label %38
38: ; preds = %24, %37
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %44
43: ; preds = %26
br label %44
44: ; preds = %43, %38, %32, %27, %18, %8
%45 = load i32, i32* %3
%46 = icmp ne i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* %3
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %47, %44
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/zcore\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"ERROR: \00"
@.str.2 = [16 x i8] c"open %s failed\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [31 x i8] c"ioctl 'get error code' failed\0A\00"
@.str.5 = [27 x i8] c"HSA - Feature not working\0A\00"
@.str.6 = [19 x i8] c"HSA - NO CPU INFO\0A\00"
@.str.7 = [13 x i8] c"HSA - ERROR\0A\00"
define i32 @dump_check_zcore() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %32, label %6
6: ; preds = %0
%7 = call i32 @ioctl(i32 %4, i32 3, i32* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %38
15: ; preds = %6
%16 = load i32, i32* %1
switch i32 %16, label %27 [
i32 0, label %38
i32 1, label %17
i32 2, label %22
]
17: ; preds = %15
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %38
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %38
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %38
32: ; preds = %0
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%37 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
br label %41
38: ; preds = %15, %27, %22, %17, %9
%39 = phi i32 [ %16, %15 ], [ -1, %17 ], [ -1, %22 ], [ -1, %27 ], [ -1, %9 ]
%40 = call i32 @close(i32 %4)
br label %41
41: ; preds = %32, %38
%42 = phi i32 [ %39, %38 ], [ -1, %32 ]
ret i32 %42
}