#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 */
typedef int time_t;

/* Variables and functions */
int /*<<< orphan*/ I2C_SLAVE;
int /*<<< orphan*/ O_RDWR;
int arduino_read_time(int, int *);
int arduino_set_time(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int client = -1;
  int ret;
  if ((client = open("/dev/i2c-1", O_RDWR)) < 0) {
    fprintf(stderr, "Failed to open the I2C device.\n");
    return 1;
  }
  if (ioctl(client, I2C_SLAVE, 0x04) < 0) {
    fprintf(stderr, "Unable to get bus access to talk to slave.\n");
    close(client);
    return 1;
  }
  time_t time;
  ret = arduino_read_time(client, &time);
  if (!ret) {
    fprintf(stdout, "time: %lu (0x%04x)\n", time, (unsigned int)time);
  } else {
    fprintf(stderr, "Failed to read the time.\n");
    close(client);
    return 1;
  }
  time = 0x05060708;
  ret = arduino_set_time(client, time);
  if (!ret) {
    fprintf(stdout, "The time has been set.\n");
  } else {
    fprintf(stderr, "Failed to set the time.\n");
    close(client);
    return 1;
  }
  close(client);
  return ret;
}


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)
movl   $0xffffffff,-0x14(%rbp)
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11c1 <main+0x61>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e6 <main+0x186>
mov    -0x14(%rbp),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    $0x4,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    120c <main+0xac>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e6 <main+0x186>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1070 <arduino_read_time@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1247 <main+0xe7>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1272 <main+0x112>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e6 <main+0x186>
movl   $0x5060708,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <arduino_set_time@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12ad <main+0x14d>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12d8 <main+0x178>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e6 <main+0x186>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11c5 <main+0x65>
mov    %eax,%ebx
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
js     11e6 <main+0x86>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1070 <arduino_read_time@plt>
test   %eax,%eax
je     120b <main+0xab>
mov    $0x1,%ebp
lea    0xeb2(%rip),%rsi
mov    0x2e10(%rip),%r14
jmp    125f <main+0xff>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    1270 <main+0x110>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%ebp
jmp    1270 <main+0x110>
mov    0x2db6(%rip),%r14
mov    (%r14),%edi
mov    0xc(%rsp),%ecx
lea    0xe37(%rip),%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
movl   $0x5060708,0xc(%rsp)
05
mov    %ebx,%edi
mov    $0x5060708,%esi
call   1030 <arduino_set_time@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
cmovne 0x2d83(%rip),%r14
lea    0xe31(%rip),%rax
lea    0xe42(%rip),%rsi
cmove  %rax,%rsi
mov    (%r14),%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Failed to open the I2C device.\0A\00"
@I2C_SLAVE = global i32 0
@.str.2 = [44 x i8] c"Unable to get bus access to talk to slave.\0A\00"
@stdout = global i32 0
@.str.3 = [20 x i8] c"time: %lu (0x%04x)\0A\00"
@.str.4 = [26 x i8] c"Failed to read the time.\0A\00"
@.str.5 = [24 x i8] c"The time has been set.\0A\00"
@.str.6 = [25 x i8] c"Failed to set the time.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %58
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32, i32* @I2C_SLAVE
%18 = call i64 @ioctl(i32 %16, i32 %17, i32 4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
store i32 1, i32* %3
br label %58
25: ; preds = %15
%26 = load i32, i32* %6
%27 = call i32 @arduino_read_time(i32 %26, i32* %8)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %25
%31 = load i32, i32* @stdout
%32 = load i32, i32* %8
%33 = load i32, i32* %8
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
br label %40
35: ; preds = %25
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
store i32 1, i32* %3
br label %58
40: ; preds = %30
store i32 84281096, i32* %8
%41 = load i32, i32* %6
%42 = load i32, i32* %8
%43 = call i32 @arduino_set_time(i32 %41, i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i32, i32* @stdout
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %54
49: ; preds = %40
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
store i32 1, i32* %3
br label %58
54: ; preds = %46
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %7
store i32 %57, i32* %3
br label %58
58: ; preds = %54, %49, %35, %20, %12
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Failed to open the I2C device.\0A\00"
@I2C_SLAVE = global i32 0
@.str.2 = [44 x i8] c"Unable to get bus access to talk to slave.\0A\00"
@stdout = global i32 0
@.str.3 = [20 x i8] c"time: %lu (0x%04x)\0A\00"
@.str.4 = [26 x i8] c"Failed to read the time.\0A\00"
@.str.5 = [24 x i8] c"The time has been set.\0A\00"
@.str.6 = [25 x i8] c"Failed to set the time.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %39
10: ; preds = %2
%11 = load i32, i32* @I2C_SLAVE
%12 = tail call i64 @ioctl(i32 %5, i32 %11, i32 4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @close(i32 %5)
br label %39
18: ; preds = %10
%19 = bitcast i32* %3 to i8*
%20 = call i32 @arduino_read_time(i32 %5, i32* %3)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = load i32, i32* %3
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %24)
store i32 84281096, i32* %3
%26 = call i32 @arduino_set_time(i32 %5, i32 84281096)
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32* @stdout, i32* @stderr
%29 = select i1 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0)
%30 = xor i1 %27, true
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %18, %22
%33 = phi i32* [ %28, %22 ], [ @stderr, %18 ]
%34 = phi i8* [ %29, %22 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), %18 ]
%35 = phi i32 [ %31, %22 ], [ 1, %18 ]
%36 = load i32, i32* %33
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* %34)
%38 = call i32 @close(i32 %5)
br label %39
39: ; preds = %32, %14, %7
%40 = phi i32 [ 1, %7 ], [ 1, %14 ], [ %35, %32 ]
ret i32 %40
}