#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_RETRIES;
int /*<<< orphan*/ I2C_TIMEOUT;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int init_at24c256_i2c(const char *device) {
  int fd = open(device, O_RDWR);
  if (fd < 0) {
    perror("Failed to open I2C device!");
    return -1;
  }
  ioctl(fd, I2C_TIMEOUT, 3);
  ioctl(fd, I2C_RETRIES, 3);
  return fd;
}


x86 assembly (clang, -O0):
<init_at24c256_i2c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1173 <init_at24c256_i2c+0x43>
lea    0xe9e(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <init_at24c256_i2c+0x75>
mov    -0x14(%rbp),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    $0x3,%edx
call   1030 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    $0x3,%edx
call   1030 <ioctl@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_at24c256_i2c>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1173 <init_at24c256_i2c+0x43>
mov    %eax,%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x3,%edx
call   1030 <ioctl@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x3,%edx
call   1030 <ioctl@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe86(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    116f <init_at24c256_i2c+0x3f>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [27 x i8] c"Failed to open I2C device!\00"
@I2C_TIMEOUT = global i32 0
@I2C_RETRIES = global i32 0
define i32 @init_at24c256_i2c(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %20
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* @I2C_TIMEOUT
%15 = call i32 @ioctl(i32 %13, i32 %14, i32 3)
%16 = load i32, i32* %4
%17 = load i32, i32* @I2C_RETRIES
%18 = call i32 @ioctl(i32 %16, i32 %17, i32 3)
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %20
20: ; preds = %12, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [27 x i8] c"Failed to open I2C device!\00"
@I2C_TIMEOUT = global i32 0
@I2C_RETRIES = global i32 0
define i32 @init_at24c256_i2c(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %1
%8 = load i32, i32* @I2C_TIMEOUT
%9 = tail call i32 @ioctl(i32 %3, i32 %8, i32 3)
%10 = load i32, i32* @I2C_RETRIES
%11 = tail call i32 @ioctl(i32 %3, i32 %10, i32 3)
br label %12
12: ; preds = %7, %5
%13 = phi i32 [ -1, %5 ], [ %3, %7 ]
ret i32 %13
}