#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*/ clear(int);
int /*<<< orphan*/ command(int, int);
int /*<<< orphan*/ expanderWrite(int, int);
int /*<<< orphan*/ home(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write4bits(int, int);
int initialize(const char *i2c_device, int addr) {
  int file = 0;
  if ((file = open(i2c_device, O_RDWR)) < 0) {
    printf("No se pudo abrir el dispositivo i2c: %s\r\n", i2c_device);
    return -1;
  }
  if (ioctl(file, I2C_SLAVE, addr) != 0) {
    printf("No se ha podido seleccionar la dirección del esclavo\r\n");
    return -1;
  }
  usleep(50000);
  expanderWrite(file, 0x08);
  usleep(1000000);
  write4bits(file, 0x03 << 4);
  usleep(4500);
  write4bits(file, 0x30);
  usleep(4500);
  write4bits(file, 0x30);
  usleep(150);
  write4bits(file, 0x20);
  command(file, 0x20 | 0x08);
  command(file, 0x08 | 0x04 | 0x00 | 0x00);
  clear(file);
  command(file, 0x04 | 0x02 | 0x00);
  home(file);
  return file;
}


x86 assembly (clang, -O0):
<initialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11e2 <initialize+0x52>
mov    -0x10(%rbp),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <initialize+0x13a>
mov    -0x18(%rbp),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
je     121a <initialize+0x8a>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ca <initialize+0x13a>
mov    $0xc350,%edi
call   10b0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x8,%esi
call   1090 <expanderWrite@plt>
mov    $0xf4240,%edi
call   10b0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x30,%esi
call   1040 <write4bits@plt>
mov    $0x1194,%edi
call   10b0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x30,%esi
call   1040 <write4bits@plt>
mov    $0x1194,%edi
call   10b0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x30,%esi
call   1040 <write4bits@plt>
mov    $0x96,%edi
call   10b0 <usleep@plt>
mov    -0x18(%rbp),%edi
mov    $0x20,%esi
call   1040 <write4bits@plt>
mov    -0x18(%rbp),%edi
mov    $0x28,%esi
call   1030 <command@plt>
mov    -0x18(%rbp),%edi
mov    $0xc,%esi
call   1030 <command@plt>
mov    -0x18(%rbp),%edi
call   10a0 <clear@plt>
mov    -0x18(%rbp),%edi
mov    $0x6,%esi
call   1030 <command@plt>
mov    -0x18(%rbp),%edi
call   1070 <home@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initialize>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     11ec <initialize+0x4c>
mov    %eax,%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14d,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
je     1207 <initialize+0x67>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    12a7 <initialize+0x107>
lea    0xe0d(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    12a7 <initialize+0x107>
mov    $0xc350,%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x8,%esi
call   10a0 <expanderWrite@plt>
mov    $0xf4240,%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x30,%esi
call   1050 <write4bits@plt>
mov    $0x1194,%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x30,%esi
call   1050 <write4bits@plt>
mov    $0x1194,%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x30,%esi
call   1050 <write4bits@plt>
mov    $0x96,%edi
call   10c0 <usleep@plt>
mov    %ebx,%edi
mov    $0x20,%esi
call   1050 <write4bits@plt>
mov    %ebx,%edi
mov    $0x28,%esi
call   1040 <command@plt>
mov    %ebx,%edi
mov    $0xc,%esi
call   1040 <command@plt>
mov    %ebx,%edi
call   10b0 <clear@plt>
mov    %ebx,%edi
mov    $0x6,%esi
call   1040 <command@plt>
mov    %ebx,%edi
call   1080 <home@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [42 x i8] c"No se pudo abrir el dispositivo i2c: %s\0D\0A\00"
@I2C_SLAVE = global i32 0
@.str.1 = [56 x i8] c"No se ha podido seleccionar la direcci\C3\B3n del esclavo\0D\0A\00"
define i32 @initialize(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %3
br label %49
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load i32, i32* @I2C_SLAVE
%17 = load i32, i32* %5
%18 = call i64 @ioctl(i32 %15, i32 %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %49
22: ; preds = %14
%23 = call i32 @usleep(i32 50000)
%24 = load i32, i32* %6
%25 = call i32 @expanderWrite(i32 %24, i32 8)
%26 = call i32 @usleep(i32 1000000)
%27 = load i32, i32* %6
%28 = call i32 @write4bits(i32 %27, i32 48)
%29 = call i32 @usleep(i32 4500)
%30 = load i32, i32* %6
%31 = call i32 @write4bits(i32 %30, i32 48)
%32 = call i32 @usleep(i32 4500)
%33 = load i32, i32* %6
%34 = call i32 @write4bits(i32 %33, i32 48)
%35 = call i32 @usleep(i32 150)
%36 = load i32, i32* %6
%37 = call i32 @write4bits(i32 %36, i32 32)
%38 = load i32, i32* %6
%39 = call i32 @command(i32 %38, i32 40)
%40 = load i32, i32* %6
%41 = call i32 @command(i32 %40, i32 12)
%42 = load i32, i32* %6
%43 = call i32 @clear(i32 %42)
%44 = load i32, i32* %6
%45 = call i32 @command(i32 %44, i32 6)
%46 = load i32, i32* %6
%47 = call i32 @home(i32 %46)
%48 = load i32, i32* %6
store i32 %48, i32* %3
br label %49
49: ; preds = %22, %20, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [42 x i8] c"No se pudo abrir el dispositivo i2c: %s\0D\0A\00"
@I2C_SLAVE = global i32 0
@str = [55 x i8] c"No se ha podido seleccionar la direcci\C3\B3n del esclavo\0D\00"
define i32 @initialize(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 ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %30
8: ; preds = %2
%9 = load i32, i32* @I2C_SLAVE
%10 = tail call i64 @ioctl(i32 %4, i32 %9, i32 %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %30
14: ; preds = %8
%15 = tail call i32 @usleep(i32 50000)
%16 = tail call i32 @expanderWrite(i32 %4, i32 8)
%17 = tail call i32 @usleep(i32 1000000)
%18 = tail call i32 @write4bits(i32 %4, i32 48)
%19 = tail call i32 @usleep(i32 4500)
%20 = tail call i32 @write4bits(i32 %4, i32 48)
%21 = tail call i32 @usleep(i32 4500)
%22 = tail call i32 @write4bits(i32 %4, i32 48)
%23 = tail call i32 @usleep(i32 150)
%24 = tail call i32 @write4bits(i32 %4, i32 32)
%25 = tail call i32 @command(i32 %4, i32 40)
%26 = tail call i32 @command(i32 %4, i32 12)
%27 = tail call i32 @clear(i32 %4)
%28 = tail call i32 @command(i32 %4, i32 6)
%29 = tail call i32 @home(i32 %4)
br label %30
30: ; preds = %14, %12, %6
%31 = phi i32 [ -1, %6 ], [ -1, %12 ], [ %4, %14 ]
ret i32 %31
}