#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*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int connect_accel(const char *devName) {
  int file = open(devName, O_RDWR);
  if (file == -1) {
    printf("error: could not open %s\n", devName);
    exit(1);
  }
  if (ioctl(file, I2C_SLAVE, (0x53)) < 0) {
    printf("error: failed to acquire bus address and or talk to slave\n");
    exit(1);
  }
  return file;
}


x86 assembly (clang, -O0):
<connect_accel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1187 <connect_accel+0x47>
mov    -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    $0x53,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11bf <connect_accel+0x7f>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_accel>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1190 <connect_accel+0x40>
mov    %eax,%ebx
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x53,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     11ab <connect_accel+0x5b>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe69(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [26 x i8] c"error: could not open %s\0A\00"
@I2C_SLAVE = global i32 0
@.str.1 = [59 x i8] c"error: failed to acquire bus address and or talk to slave\0A\00"
define i32 @connect_accel(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @I2C_SLAVE
%16 = call i64 @ioctl(i32 %14, i32 %15, i32 83)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [26 x i8] c"error: could not open %s\0A\00"
@I2C_SLAVE = global i32 0
@str = [58 x i8] c"error: failed to acquire bus address and or talk to slave\00"
define i32 @connect_accel(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = load i32, i32* @I2C_SLAVE
%10 = tail call i64 @ioctl(i32 %3, i32 %9, i32 83)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
ret i32 %3
}