#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ioctl(int, int, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int init(char *device, int addr) {
  int file;
  long funcs;
  if ((file = open(device, O_RDWR)) < 0) {
    fprintf(stderr, "Error: Could not open file %s\n", device);
    return 0;
  }
  if (ioctl(file, 0x0705, &funcs) < 0) {
    fprintf(stderr,
            "Error: Could not get the adapter functionality matrix: %s\n",
            strerror(errno));
    close(file);
    return 0;
  }
  if (ioctl(file, 0x0703, addr) < 0) {
    fprintf(stderr, "Error: Cannot communicate with slave: %s\n",
            strerror(errno));
    close(file);
    return 0;
  }
  return file;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11a2 <init+0x52>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <init+0x111>
mov    -0x18(%rbp),%edi
mov    $0x705,%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11ff <init+0xaf>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <init+0x111>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    $0x703,%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    125b <init+0x10b>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe18(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <init+0x111>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11a8 <init+0x58>
mov    %eax,%ebp
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    $0x705,%esi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11c4 <init+0x74>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    $0x703,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     11e5 <init+0x95>
mov    %ebp,%ebx
jmp    1216 <init+0xc6>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %ebx,%ebx
jmp    1216 <init+0xc6>
mov    0x2e0d(%rip),%rax
mov    (%rax),%r14d
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3c(%rip),%rsi
jmp    1204 <init+0xb4>
mov    0x2dec(%rip),%rax
mov    (%rax),%r14d
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe56(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error: Could not open file %s\0A\00"
@.str.1 = [59 x i8] c"Error: Could not get the adapter functionality matrix: %s\0A\00"
@errno = global i32 0
@.str.2 = [42 x i8] c"Error: Cannot communicate with slave: %s\0A\00"
define i32 @init(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %41
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i64 (i32, i32, ...) @ioctl(i32 %17, i32 1797, i64* %7)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 0, i32* %3
br label %41
27: ; preds = %16
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = call i64 (i32, i32, ...) @ioctl(i32 %28, i32 1795, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
store i32 0, i32* %3
br label %41
39: ; preds = %27
%40 = load i32, i32* %6
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %32, %20, %12
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error: Could not open file %s\0A\00"
@.str.1 = [59 x i8] c"Error: Could not get the adapter functionality matrix: %s\0A\00"
@errno = global i32 0
@.str.2 = [42 x i8] c"Error: Cannot communicate with slave: %s\0A\00"
define i32 @init(i8* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %29
11: ; preds = %2
%12 = call i64 (i32, i32, ...) @ioctl(i32 %6, i32 1797, i64* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @close(i32 %6)
br label %29
20: ; preds = %11
%21 = call i64 (i32, i32, ...) @ioctl(i32 %6, i32 1795, i32 %1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = call i32 @close(i32 %6)
br label %29
29: ; preds = %20, %23, %14, %8
%30 = phi i32 [ 0, %8 ], [ 0, %14 ], [ 0, %23 ], [ %6, %20 ]
ret i32 %30
}