#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);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  printf("**** TPA81 test program ****,\n");
  int fd;
  char *fileName = "/dev/i2c-1";
  int address = 0x68;
  unsigned char buf[10];
  if ((fd = open(fileName, O_RDWR)) < 0) {
    printf("Failed to open i2c port\n");
    exit(1);
  }
  if (ioctl(fd, I2C_SLAVE, address) < 0) {
    printf("Unable to get bus access to talk to slave\n");
    exit(1);
  }
  buf[0] = 0;
  if ((write(fd, buf, 1)) != 1) {
    printf("Error writing to i2c slave\n");
    exit(1);
  }
  if (read(fd, buf, 10) != 10) {
    printf("Unable to read from slave\n");
    exit(1);
  } else {
    printf("Software v: %u \n", buf[0]);
    printf("Ambient temperature: %u \n", buf[1]);
    printf("Temperature readings:\n");
    printf("%2u, %2u, %2u, %2u \n", buf[2], buf[3], buf[4], buf[5]);
    printf("%2u, %2u, %2u, %2u\n", buf[6], buf[7], buf[8], buf[9]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe94(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x68,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11cc <main+0x6c>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1202 <main+0xa2>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movb   $0x0,-0x2e(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     1238 <main+0xd8>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
cmp    $0xa,%eax
je     126a <main+0x10a>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movzbl -0x2e(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x2d(%rbp),%esi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x2c(%rbp),%esi
movzbl -0x2b(%rbp),%edx
movzbl -0x2a(%rbp),%ecx
movzbl -0x29(%rbp),%r8d
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x28(%rbp),%esi
movzbl -0x27(%rbp),%edx
movzbl -0x26(%rbp),%ecx
movzbl -0x25(%rbp),%r8d
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1277 <main+0x107>
mov    %eax,%ebx
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x68,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     1280 <main+0x110>
movb   $0x0,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    1289 <main+0x119>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1070 <read@plt>
cmp    $0xa,%eax
jne    1292 <main+0x122>
movzbl 0x6(%rsp),%esi
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rsp),%esi
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
movzbl 0x8(%rsp),%esi
movzbl 0x9(%rsp),%edx
movzbl 0xa(%rsp),%ecx
movzbl 0xb(%rsp),%r8d
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xc(%rsp),%esi
movzbl 0xd(%rsp),%edx
movzbl 0xe(%rsp),%ecx
movzbl 0xf(%rsp),%r8d
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe74(%rip),%rdi
jmp    1299 <main+0x129>
lea    0xe41(%rip),%rdi
jmp    1299 <main+0x129>
lea    0xe1d(%rip),%rdi
jmp    1299 <main+0x129>
lea    0xdfa(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"**** TPA81 test program ****,\0A\00"
@.str.1 = [11 x i8] c"/dev/i2c-1\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 = [43 x i8] c"Unable to get bus access to talk to slave\0A\00"
@.str.4 = [28 x i8] c"Error writing to i2c slave\0A\00"
@.str.5 = [27 x i8] c"Unable to read from slave\0A\00"
@.str.6 = [17 x i8] c"Software v: %u \0A\00"
@.str.7 = [26 x i8] c"Ambient temperature: %u \0A\00"
@.str.8 = [23 x i8] c"Temperature readings:\0A\00"
@.str.9 = [21 x i8] c"%2u, %2u, %2u, %2u \0A\00"
@.str.10 = [20 x i8] c"%2u, %2u, %2u, %2u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 104, i32* %8
%11 = load i8*, i8** %7
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%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* %6
%20 = load i32, i32* @I2C_SLAVE
%21 = load i32, i32* %8
%22 = call i64 @ioctl(i32 %19, i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
store i8 0, i8* %28
%29 = load i32, i32* %6
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%31 = call i32 @write(i32 %29, i8* %30, i32 1)
%32 = icmp ne i32 %31, 1
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i32, i32* %6
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 10)
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 1
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 2
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 3
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 4
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 5
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %56, i32 %59, i32 %62, i32 %65)
%67 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 6
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 7
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 8
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 9
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %69, i32 %72, i32 %75, i32 %78)
br label %80
80: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.6 = [17 x i8] c"Software v: %u \0A\00"
@.str.7 = [26 x i8] c"Ambient temperature: %u \0A\00"
@.str.9 = [21 x i8] c"%2u, %2u, %2u, %2u \0A\00"
@.str.10 = [20 x i8] c"%2u, %2u, %2u, %2u\0A\00"
@str = [30 x i8] c"**** TPA81 test program ****,\00"
@str.11 = [22 x i8] c"Temperature readings:\00"
@str.12 = [26 x i8] c"Unable to read from slave\00"
@str.13 = [27 x i8] c"Error writing to i2c slave\00"
@str.14 = [42 x i8] c"Unable to get bus access to talk to slave\00"
@str.15 = [24 x i8] c"Failed to open i2c port\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, 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.1, 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.15, 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 104)
%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 ([42 x i8], [42 x i8]* @str.14, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
store i8 0, i8* %5
%20 = call i32 @write(i32 %7, i8* %5, i32 1)
%21 = icmp eq i32 %20, 1
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = call i32 @read(i32 %7, i8* %5, i32 10)
%27 = icmp eq i32 %26, 10
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %25
%32 = load i8, i8* %5
%33 = zext i8 %32 to i32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %37)
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.11, i64 0, i64 0))
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 3
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 4
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 5
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %42, i32 %45, i32 %48, i32 %51)
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 8
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 9
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0), i32 %55, i32 %58, i32 %61, i32 %64)
ret i32 0
}