#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 /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
void main() {
  int file;
  char *bus = "/dev/i2c-1";
  if ((file = open(bus, O_RDWR)) < 0) {
    printf("Failed to open the bus. \n");
    exit(1);
  }
  ioctl(file, I2C_SLAVE, 0x39);
  char config[2] = {0};
  config[0] = 0x00 | 0x80;
  config[1] = 0x03;
  write(file, config, 2);
  config[0] = 0x01 | 0x80;
  config[1] = 0x02;
  write(file, config, 2);
  sleep(1);
  char reg[1] = {0x0C | 0x80};
  write(file, reg, 1);
  char data[4] = {0};
  if (read(file, data, 4) != 4) {
    printf("Erorr : Input/output Erorr \n");
  } else {
    float ch0 = (data[1] * 256 + data[0]);
    float ch1 = (data[3] * 256 + data[2]);
    printf("%.2f,%.2f\n", ch0, ch1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11c9 <main+0x49>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    $0x39,%edx
call   1060 <ioctl@plt>
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
movb   $0x80,-0x12(%rbp)
movb   $0x3,-0x11(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movb   $0x81,-0x12(%rbp)
movb   $0x2,-0x11(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    0xe1c(%rip),%al
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0x4,%eax
je     1282 <main+0x102>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ce <main+0x14e>
movsbl -0x16(%rbp),%eax
shl    $0x8,%eax
movsbl -0x17(%rbp),%ecx
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x1c(%rbp)
movsbl -0x14(%rbp),%eax
shl    $0x8,%eax
movsbl -0x15(%rbp),%ecx
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x20(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd7b(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
lea    0xe69(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1280 <main+0x100>
mov    %eax,%ebx
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x39,%edx
call   1060 <ioctl@plt>
movw   $0x380,0x16(%rsp)
lea    0x16(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
movw   $0x281,0x16(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
movb   $0x8c,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
movl   $0x0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0x4,%eax
jne    126d <main+0xed>
movsbl 0x11(%rsp),%eax
shl    $0x8,%eax
movsbl 0x10(%rsp),%ecx
add    %eax,%ecx
cvtsi2ss %ecx,%xmm0
movsbl 0x13(%rsp),%eax
shl    $0x8,%eax
movsbl 0x12(%rsp),%ecx
add    %eax,%ecx
cvtsi2ss %ecx,%xmm1
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
lea    0xdac(%rip),%rdi
mov    $0x2,%al
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>
lea    0xda2(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>
lea    0xdab(%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"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"Failed to open the bus. \0A\00"
@I2C_SLAVE = global i32 0
@__const.main.reg = [1 x i8] c"\8C"
@.str.2 = [29 x i8] c"Erorr : Input/output Erorr \0A\00"
@.str.3 = [11 x i8] c"%.2f,%.2f\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [2 x i8]
%4 = alloca [1 x i8]
%5 = alloca [4 x i8]
%6 = alloca float
%7 = alloca float
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %2
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %1
%17 = load i32, i32* @I2C_SLAVE
%18 = call i32 @ioctl(i32 %16, i32 %17, i32 57)
%19 = bitcast [2 x i8]* %3 to i8*
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 -128, i8* %20
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 3, i8* %21
%22 = load i32, i32* %1
%23 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%24 = call i32 @write(i32 %22, i8* %23, i32 2)
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 -127, i8* %25
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 2, i8* %26
%27 = load i32, i32* %1
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%29 = call i32 @write(i32 %27, i8* %28, i32 2)
%30 = call i32 @sleep(i32 1)
%31 = bitcast [1 x i8]* %4 to i8*
%32 = load i32, i32* %1
%33 = getelementptr inbounds [1 x i8], [1 x i8]* %4, i64 0, i64 0
%34 = call i32 @write(i32 %32, i8* %33, i32 1)
%35 = bitcast [4 x i8]* %5 to i8*
%36 = load i32, i32* %1
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 4)
%39 = icmp ne i32 %38, 4
br i1 %39, label %40, label %42
40: ; preds = %15
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %66
42: ; preds = %15
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = mul nsw i32 %45, 256
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = add nsw i32 %46, %49
%51 = sitofp i32 %50 to float
store float %51, float* %6
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = mul nsw i32 %54, 256
%56 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = add nsw i32 %55, %58
%60 = sitofp i32 %59 to float
store float %60, float* %7
%61 = load float, float* %6
%62 = fpext float %61 to double
%63 = load float, float* %7
%64 = fpext float %63 to double
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %62, double %64)
br label %66
66: ; preds = %42, %40
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@O_RDWR = global i32 0
@I2C_SLAVE = global i32 0
@.str.3 = [11 x i8] c"%.2f,%.2f\0A\00"
@str = [28 x i8] c"Erorr : Input/output Erorr \00"
@str.4 = [25 x i8] c"Failed to open the bus. \00"
define void @main() {
%1 = alloca i16
%2 = alloca [1 x i8]
%3 = alloca i32
%4 = bitcast i32* %3 to [4 x i8]*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = bitcast i16* %1 to [2 x i8]*
%13 = load i32, i32* @I2C_SLAVE
%14 = tail call i32 @ioctl(i32 %6, i32 %13, i32 57)
%15 = bitcast i16* %1 to i8*
store i16 896, i16* %1
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %12, i64 0, i64 1
%17 = call i32 @write(i32 %6, i8* %15, i32 2)
store i8 -127, i8* %15
store i8 2, i8* %16
%18 = call i32 @write(i32 %6, i8* %15, i32 2)
%19 = tail call i32 @sleep(i32 1)
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
store i8 -116, i8* %20
%21 = call i32 @write(i32 %6, i8* %20, i32 1)
%22 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%23 = call i32 @read(i32 %6, i8* %22, i32 4)
%24 = icmp eq i32 %23, 4
br i1 %24, label %27, label %25
25: ; preds = %11
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %48
27: ; preds = %11
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = shl nsw i32 %30, 8
%32 = load i8, i8* %22
%33 = sext i8 %32 to i32
%34 = add nsw i32 %31, %33
%35 = sitofp i32 %34 to float
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = shl nsw i32 %38, 8
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = add nsw i32 %39, %42
%44 = sitofp i32 %43 to float
%45 = fpext float %35 to double
%46 = fpext float %44 to double
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), double %45, double %46)
br label %48
48: ; preds = %27, %25
ret void
}