#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_TENBIT;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ get_date(int);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ set_date(int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  int fd, ret;
  fd = open("/dev/i2c-2", O_RDWR);
  if (fd < 0)
    die("cannot open device "
        "/dev/i2c-2"
        "\n");
  ret = ioctl(fd, I2C_TENBIT, 0);
  if (ret < 0)
    die("set address mode fail\n");
  ret = ioctl(fd, I2C_SLAVE, 0x68);
  if (ret < 0)
    die("set address fail\n");
  set_date(fd);
  for (;;) {
    get_date(fd);
    sleep(1);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a4 <main+0x44>
lea    0xe6c(%rip),%rdi
call   1060 <die@plt>
mov    -0x14(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d0 <main+0x70>
lea    0xe5f(%rip),%rdi
call   1060 <die@plt>
mov    -0x14(%rbp),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    $0x68,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ff <main+0x9f>
lea    0xe47(%rip),%rdi
call   1060 <die@plt>
mov    -0x14(%rbp),%edi
call   1040 <set_date@plt>
mov    -0x14(%rbp),%edi
call   1070 <get_date@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1207 <main+0xa7>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1188 <main+0x28>
lea    0xe88(%rip),%rdi
call   1060 <die@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
jns    11aa <main+0x4a>
lea    0xe85(%rip),%rdi
call   1060 <die@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x68,%edx
call   1030 <ioctl@plt>
test   %eax,%eax
jns    11cf <main+0x6f>
lea    0xe77(%rip),%rdi
call   1060 <die@plt>
mov    %ebx,%edi
call   1040 <set_date@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1070 <get_date@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11e0 <main+0x80>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_RDWR = global i32 0
@.str.1 = [31 x i8] c"cannot open device /dev/i2c-2\0A\00"
@I2C_TENBIT = global i32 0
@.str.2 = [23 x i8] c"set address mode fail\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [18 x i8] c"set address fail\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* %6
%16 = load i32, i32* @I2C_TENBIT
%17 = call i32 @ioctl(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = load i32, i32* %6
%24 = load i32, i32* @I2C_SLAVE
%25 = call i32 @ioctl(i32 %23, i32 %24, i32 104)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = load i32, i32* %6
%32 = call i32 @set_date(i32 %31)
br label %33
33: ; preds = %33, %30
%34 = load i32, i32* %6
%35 = call i32 @get_date(i32 %34)
%36 = call i32 @sleep(i32 1)
br label %33
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_RDWR = global i32 0
@.str.1 = [31 x i8] c"cannot open device /dev/i2c-2\0A\00"
@I2C_TENBIT = global i32 0
@.str.2 = [23 x i8] c"set address mode fail\0A\00"
@I2C_SLAVE = global i32 0
@.str.3 = [18 x i8] c"set address fail\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = load i32, i32* @I2C_TENBIT
%10 = tail call i32 @ioctl(i32 %4, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* @I2C_SLAVE
%16 = tail call i32 @ioctl(i32 %4, i32 %15, i32 104)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @set_date(i32 %4)
br label %22
22: ; preds = %22, %20
%23 = tail call i32 @get_date(i32 %4)
%24 = tail call i32 @sleep(i32 1)
br label %22
}