#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 opt3001_init(char *, int);
int opt3001_read(float *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, float, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ time(int *);
int main() {
  float lux;
  time_t t;
  int r;
  r = opt3001_init("/dev/i2c-1", 0x45);
  if (r != 0) {
    perror("cannot initialize i2c device: ");
    return -1;
  }
  while (1) {
    time(&t);
    r = opt3001_read(&lux);
    printf("%d: %.4f (err=%d)\n", t, lux, r);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x45,%esi
call   1030 <opt3001_init@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11a4 <main+0x44>
lea    0xe77(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    11a9 <main+0x49>
lea    -0xc(%rbp),%rdi
call   1060 <time@plt>
lea    -0x8(%rbp),%rdi
call   1050 <opt3001_read@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%esi
movss  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%edx
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11a9 <main+0x49>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
mov    $0x45,%esi
call   1030 <opt3001_init@plt>
test   %eax,%eax
jne    11c0 <main+0x60>
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xe9b(%rip),%rbx
nop
mov    %r14,%rdi
call   1060 <time@plt>
mov    %r15,%rdi
call   1050 <opt3001_read@plt>
mov    0x8(%rsp),%esi
movss  0xc(%rsp),%xmm0
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1190 <main+0x30>
lea    0xe44(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [31 x i8] c"cannot initialize i2c device: \00"
@.str.2 = [19 x i8] c"%d: %.4f (err=%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @opt3001_init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 69)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
10: ; preds = %0
br label %11
11: ; preds = %10, %11
%12 = call i32 @time(i32* %3)
%13 = call i32 @opt3001_read(float* %2)
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = load float, float* %2
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %14, float %15, i32 %16)
%18 = call i32 @sleep(i32 1)
br label %11
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [31 x i8] c"cannot initialize i2c device: \00"
@.str.2 = [19 x i8] c"%d: %.4f (err=%d)\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca i32
%3 = bitcast float* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @opt3001_init(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 69)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
9: ; preds = %0, %9
%10 = call i32 @time(i32* %2)
%11 = call i32 @opt3001_read(float* %1)
%12 = load i32, i32* %2
%13 = load float, float* %1
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %12, float %13, i32 %11)
%15 = call i32 @sleep(i32 1)
br label %9
}