#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);
int i2c_smbus_read_word_data(int, char);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int write(int, char *, int);
main() {
  printf("\nHello World!\n");
  int file;
  int adapter_nr = 1;
  char filename[20];
  snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
  file = open(filename, O_RDWR);
  if (file < 0) {
    exit(1);
  }
  int addr = 0x40;
  if (ioctl(file, I2C_SLAVE, addr) < 0) {
    exit(1);
  }
  char ina_reg = 0x0;
  int res;
  char buf[10];
  buf[0] = ina_reg;
  buf[1] = 0xff;
  buf[2] = 0x4f;
  if (write(file, buf, 3) != 3) {
  }
  if (read(file, buf, 1) != 1) {
  } else {
    printf("Read: 0x%04x\n", buf[0]);
  }
  res = i2c_smbus_read_word_data(file, ina_reg);
  if (res < 0) {
  } else {
    printf("Read: 0x%04x\n", res);
  }
  printf("\nGoodbye World!\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x13,%esi
lea    0xe58(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11e5 <main+0x65>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x40,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1214 <main+0x94>
mov    $0x1,%edi
call   10a0 <exit@plt>
movb   $0x0,-0x25(%rbp)
mov    -0x25(%rbp),%al
mov    %al,-0x36(%rbp)
movb   $0xff,-0x35(%rbp)
movb   $0x4f,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0x3,%edx
call   1030 <write@plt>
cmp    $0x3,%eax
je     1245 <main+0xc5>
jmp    1245 <main+0xc5>
mov    -0x8(%rbp),%edi
lea    -0x36(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x1,%eax
je     1264 <main+0xe4>
jmp    1276 <main+0xf6>
movsbl -0x36(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
movsbl -0x25(%rbp),%esi
call   1080 <i2c_smbus_read_word_data@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1294 <main+0x114>
jmp    12a5 <main+0x125>
mov    -0x2c(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe56(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x13,%esi
mov    $0x1,%ecx
call   1060 <snprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1270 <main+0xe0>
mov    %eax,%ebx
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x40,%edx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1270 <main+0xe0>
movw   $0xff00,0x6(%rsp)
movb   $0x4f,0x8(%rsp)
lea    0x6(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
jne    123d <main+0xad>
movsbl 0x6(%rsp),%esi
lea    0xdd6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1090 <i2c_smbus_read_word_data@plt>
test   %eax,%eax
js     125a <main+0xca>
lea    0xdbb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"\0AHello World!\0A\00"
@.str.1 = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [14 x i8] c"Read: 0x%04x\0A\00"
@.str.3 = [17 x i8] c"\0AGoodbye World!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca [10 x i8]
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 @snprintf(i8* %10, i32 19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
store i32 64, i32* %5
%21 = load i32, i32* %2
%22 = load i32, i32* @I2C_SLAVE
%23 = load i32, i32* %5
%24 = call i64 @ioctl(i32 %21, i32 %22, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
store i8 0, i8* %6
%29 = load i8, i8* %6
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
store i8 %29, i8* %30
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 1
store i8 -1, i8* %31
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 2
store i8 79, i8* %32
%33 = load i32, i32* %2
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%35 = call i32 @write(i32 %33, i8* %34, i32 3)
%36 = icmp ne i32 %35, 3
br i1 %36, label %37, label %38
37: ; preds = %28
br label %38
38: ; preds = %37, %28
%39 = load i32, i32* %2
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 1)
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %38
br label %49
44: ; preds = %38
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %44, %43
%50 = load i32, i32* %2
%51 = load i8, i8* %6
%52 = call i32 @i2c_smbus_read_word_data(i32 %50, i8 signext %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %49
br label %59
56: ; preds = %49
%57 = load i32, i32* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %56, %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"/dev/i2c-%d\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.2 = [14 x i8] c"Read: 0x%04x\0A\00"
@str = [14 x i8] c"\0AHello World!\00"
@str.4 = [16 x i8] c"\0AGoodbye World!\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [10 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1)
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* @I2C_SLAVE
%13 = call i64 @ioctl(i32 %7, i32 %12, i32 64)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 -1, i8* %19
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 79, i8* %20
%21 = call i32 @write(i32 %7, i8* %18, i32 3)
%22 = call i32 @read(i32 %7, i8* %18, i32 1)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8, i8* %18
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %17, %24
%29 = call i32 @i2c_smbus_read_word_data(i32 %7, i8 signext 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %33
33: ; preds = %28, %31
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}