#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;
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int serial_open(char *device, int highspeed) {
  int fd = -1;
  int ret;
  fd = open(device, O_RDWR);
  if (fd < 0) {
    printf("device not found[%s]\n", device);
    return fd;
  }
  if (ioctl(fd, I2C_SLAVE, 0x27) < 0) {
    printf("unable to get bus access to talk to slave[0x%02x]\n", 0x27);
    return fd;
  }
  printf("%s: i2c mode\n", device);
  return fd;
}


x86 assembly (clang, -O0):
<serial_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1182 <serial_open+0x52>
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <serial_open+0xa8>
mov    -0x18(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    $0x27,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11c0 <serial_open+0x90>
lea    0xe6d(%rip),%rdi
mov    $0x27,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <serial_open+0xa8>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     116e <serial_open+0x3e>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x27,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     1181 <serial_open+0x51>
lea    0xedd(%rip),%rdi
jmp    1175 <serial_open+0x45>
lea    0xe8b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1194 <serial_open+0x64>
lea    0xe8e(%rip),%rdi
mov    $0x27,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [22 x i8] c"device not found[%s]\0A\00"
@I2C_SLAVE = global i32 0
@.str.1 = [51 x i8] c"unable to get bus access to talk to slave[0x%02x]\0A\00"
@.str.2 = [14 x i8] c"%s: i2c mode\0A\00"
define i32 @serial_open(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 -1, i32* %6
%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 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %6
store i32 %16, i32* %3
br label %29
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i32, i32* @I2C_SLAVE
%20 = call i64 @ioctl(i32 %18, i32 %19, i32 39)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 39)
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %29
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %25, %22, %13
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [22 x i8] c"device not found[%s]\0A\00"
@I2C_SLAVE = global i32 0
@.str.1 = [51 x i8] c"unable to get bus access to talk to slave[0x%02x]\0A\00"
@.str.2 = [14 x i8] c"%s: i2c mode\0A\00"
define i32 @serial_open(i8* %0, i32 %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
8: ; preds = %2
%9 = load i32, i32* @I2C_SLAVE
%10 = tail call i64 @ioctl(i32 %4, i32 %9, i32 39)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 39)
br label %16
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %12, %6
ret i32 %4
}