#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*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int const);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int main(int argc, char **argv) {
  const char *i2cDevice = "/dev/i2c-1";
  const int i2cAddress = 0x07;
  unsigned char buf[8];
  int fd;
  printf("***** RPi i2c Arduino test *****\n");
  if ((fd = open(i2cDevice, O_RDWR)) < 0) {
    printf("Failed to open i2c port\n");
    exit(1);
  }
  if (ioctl(fd, I2C_SLAVE, i2cAddress) < 0) {
    printf("Unable to configure i2c address\n");
    exit(1);
  }
  if (read(fd, buf, 8) != 8) {
    printf("Short read from i2c\n");
    exit(1);
  }
  printf("%d  %d  %d  %d  %d  %d  %d  %d\n", (int)buf[0], (int)buf[1],
         (int)buf[2], (int)buf[3], (int)buf[4], (int)buf[5], (int)buf[6],
         (int)buf[7]);
  close(fd);
  printf("***** RPi i2c Arduino end *****\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x7,-0x1c(%rbp)
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    11cc <main+0x6c>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    $0x7,%edx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1204 <main+0xa4>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
cmp    $0x8,%eax
je     1236 <main+0xd6>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movzbl -0x24(%rbp),%esi
movzbl -0x23(%rbp),%edx
movzbl -0x22(%rbp),%ecx
movzbl -0x21(%rbp),%r8d
movzbl -0x20(%rbp),%r9d
movzbl -0x1f(%rbp),%r11d
movzbl -0x1e(%rbp),%r10d
movzbl -0x1d(%rbp),%eax
lea    0xe1b(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1236 <main+0xc6>
mov    %eax,%ebx
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x7,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     123f <main+0xcf>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <read@plt>
cmp    $0x8,%eax
jne    1248 <main+0xd8>
movzbl (%rsp),%esi
movzbl 0x1(%rsp),%edx
movzbl 0x2(%rsp),%ecx
movzbl 0x3(%rsp),%r8d
movzbl 0x4(%rsp),%r9d
movzbl 0x5(%rsp),%r10d
movzbl 0x6(%rsp),%r11d
movzbl 0x7(%rsp),%r14d
sub    $0x8,%rsp
lea    0xe03(%rip),%rdi
xor    %eax,%eax
push   %r14
push   %r11
push   %r10
call   1040 <printf@plt>
add    $0x20,%rsp
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe63(%rip),%rdi
jmp    124f <main+0xdf>
lea    0xe3a(%rip),%rdi
jmp    124f <main+0xdf>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.5 = [32 x i8] c"%d %d %d %d %d %d %d %d\0A\00"
@str = [33 x i8] c"***** RPi i2c Arduino test *****\00"
@str.7 = [32 x i8] c"***** RPi i2c Arduino end *****\00"
@str.8 = [20 x i8] c"Short read from i2c\00"
@str.9 = [32 x i8] c"Unable to configure i2c address\00"
@str.10 = [24 x i8] c"Failed to open i2c port\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32, i32* @I2C_SLAVE
%14 = tail call i64 @ioctl(i32 %7, i32 %13, i32 7)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = call i32 @read(i32 %7, i8* %4, i32 8)
%21 = icmp eq i32 %20, 8
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %30, i32 %33, i32 %36, i32 %39, i32 %42, i32 %45, i32 %48)
%50 = tail call i32 @close(i32 %7)
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}