#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*/ I2C_SLAVE_FORCE;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int set_slave_addr(int file, int address, int force) {
  if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
    fprintf(stderr, "Error: Could not set address to 0x%02x: %s\n", address,
            strerror(errno));
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_slave_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1162 <set_slave_addr+0x32>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    116e <set_slave_addr+0x3e>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11ce <set_slave_addr+0x9e>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2e04(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <set_slave_addr+0xa5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_slave_addr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
test   %edx,%edx
jne    1143 <set_slave_addr+0x13>
mov    0x2e9f(%rip),%rax
jmp    114a <set_slave_addr+0x1a>
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edx
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    118d <set_slave_addr+0x5d>
mov    0x2e6c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e5b(%rip),%r14
mov    (%r14),%edi
call   1050 <strerror@plt>
lea    0xe84(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
sub    (%r14),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@I2C_SLAVE_FORCE = global i32 0
@I2C_SLAVE = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error: Could not set address to 0x%02x: %s\0A\00"
@errno = global i32 0
define i32 @set_slave_addr(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32, i32* @I2C_SLAVE_FORCE
br label %15
13: ; preds = %3
%14 = load i32, i32* @I2C_SLAVE
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
%17 = load i32, i32* %6
%18 = call i64 @ioctl(i32 %8, i32 %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* %6
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %24)
%26 = load i32, i32* @errno
%27 = sub nsw i32 0, %26
store i32 %27, i32* %4
br label %29
28: ; preds = %15
store i32 0, i32* %4
br label %29
29: ; preds = %28, %20
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@I2C_SLAVE_FORCE = global i32 0
@I2C_SLAVE = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error: Could not set address to 0x%02x: %s\0A\00"
@errno = global i32 0
define i32 @set_slave_addr(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = load i32, i32* @I2C_SLAVE_FORCE
%6 = load i32, i32* @I2C_SLAVE
%7 = select i1 %4, i32 %6, i32 %5
%8 = tail call i64 @ioctl(i32 %0, i32 %7, i32 %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %13)
%15 = load i32, i32* @errno
%16 = sub nsw i32 0, %15
br label %17
17: ; preds = %3, %10
%18 = phi i32 [ %16, %10 ], [ 0, %3 ]
ret i32 %18
}