#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*/ am2315_close(void *);
void *am2315_init(int, char *);
int /*<<< orphan*/ am2315_read_data(void *, float *, float *);
int /*<<< orphan*/ printf(char *, float, ...);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  char *i2c_device = "/dev/i2c-1";
  int address = 0x5c;
  void *am = am2315_init(address, i2c_device);
  if (am != NULL) {
    float temperature, humidity;
    int i;
    for (i = 0; i < 10; i++) {
      printf("-------- %i ---------\n", i);
      usleep(2 * 1000 * 1000);
      am2315_read_data(am, &temperature, &humidity);
      printf("temperature = %f, humidity = %f\n", temperature, humidity);
    }
    am2315_close(am);
  }
  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    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x5c,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <am2315_init@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1205 <main+0xb5>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    11fc <main+0xac>
cvtsi2ssl -0x34(%rbp),%xmm0
lea    0xe5b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1e8480,%edi
call   1070 <usleep@plt>
mov    -0x28(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <am2315_read_data@plt>
movss  -0x2c(%rbp),%xmm0
movss  -0x30(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe3b(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119a <main+0x4a>
mov    -0x28(%rbp),%rdi
call   1050 <am2315_close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rsi
mov    $0x5c,%edi
call   1030 <am2315_init@plt>
test   %rax,%rax
je     11e2 <main+0x92>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe8e(%rip),%r14
lea    0x4(%rsp),%r15
mov    %rsp,%r12
lea    0xe96(%rip),%r13
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x1e8480,%edi
call   1070 <usleep@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <am2315_read_data@plt>
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mov    %r13,%rdi
mov    $0x2,%al
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1050 <am2315_close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [23 x i8] c"-------- %i ---------\0A\00"
@.str.2 = [33 x i8] c"temperature = %f, humidity = %f\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 i8*
%9 = alloca float
%10 = alloca float
%11 = 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 92, i32* %7
%12 = load i32, i32* %7
%13 = load i8*, i8** %6
%14 = call i8* @am2315_init(i32 %12, i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %38
17: ; preds = %2
store i32 0, i32* %11
br label %18
18: ; preds = %32, %17
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = load i32, i32* %11
%23 = sitofp i32 %22 to float
%24 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), float %23)
%25 = call i32 @usleep(i32 2000000)
%26 = load i8*, i8** %8
%27 = call i32 @am2315_read_data(i8* %26, float* %9, float* %10)
%28 = load float, float* %9
%29 = load float, float* %10
%30 = fpext float %29 to double
%31 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), float %28, double %30)
br label %32
32: ; preds = %21
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %18
35: ; preds = %18
%36 = load i8*, i8** %8
%37 = call i32 @am2315_close(i8* %36)
br label %38
38: ; preds = %35, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-1\00"
@.str.1 = [23 x i8] c"-------- %i ---------\0A\00"
@.str.2 = [33 x i8] c"temperature = %f, humidity = %f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca float
%4 = alloca float
%5 = tail call i8* @am2315_init(i32 92, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %24, label %7
7: ; preds = %2
%8 = bitcast float* %3 to i8*
%9 = bitcast float* %4 to i8*
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 0, %7 ], [ %20, %10 ]
%12 = sitofp i32 %11 to float
%13 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), float %12)
%14 = call i32 @usleep(i32 2000000)
%15 = call i32 @am2315_read_data(i8* %5, float* %3, float* %4)
%16 = load float, float* %3
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = call i32 (i8*, float, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), float %16, double %18)
%20 = add nuw nsw i32 %11, 1
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %10
22: ; preds = %10
%23 = call i32 @am2315_close(i8* %5)
br label %24
24: ; preds = %22, %2
ret i32 0
}