#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 scalar_t__ int8_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int init_adt74x0(int, int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read_adt74x0(int, int, double *);
int /*<<< orphan*/ usleep(int);
int main(int argc, const char *argv[]) {
  const char default_file[] = "/dev/i2c-0";
  const char *filename = (argc > 1) ? argv[1] : default_file;
  printf("# Scanning %s for ADT74x0...\n", filename);
  int file = open(filename, O_RDWR);
  if (file < 0) {
    printf("Unable to open %s\n", filename);
    exit(1);
  }
  int8_t devs[128];
  for (int i = 0; i < 128; i++)
    devs[i] = (i >= 0x48 && i <= 0x4b) ? 1 : 0;
  for (int i = 0; i < 128; i++) {
    if (devs[i] <= 0)
      continue;
    int stat = init_adt74x0(file, i);
    if (stat < 0)
      devs[i] = stat;
  }
  usleep(1000000);
  for (int i = 0; i < 128; i++) {
    if (devs[i] <= 0)
      continue;
    double t;
    int stat = read_adt74x0(file, i, &t);
    if (stat < 0) {
      printf("# 0x%02x error %d\n", i, stat);
    } else {
      printf("0x%02x %.5fC\n", i, t);
    }
  }
  close(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x1b(%rbp)
mov    0xe6d(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xe65(%rip),%al
mov    %al,-0x11(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c6 <main+0x56>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x458(%rbp)
jmp    11d1 <main+0x61>
lea    -0x1b(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1229 <main+0xb9>
mov    -0x28(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x434(%rbp)
cmpl   $0x80,-0x434(%rbp)
jge    12a1 <main+0x131>
xor    %eax,%eax
cmpl   $0x48,-0x434(%rbp)
mov    %al,-0x459(%rbp)
jl     1268 <main+0xf8>
cmpl   $0x4b,-0x434(%rbp)
setle  %al
mov    %al,-0x459(%rbp)
mov    -0x459(%rbp),%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
movslq %eax,%rcx
movslq -0x434(%rbp),%rax
mov    %rcx,-0x430(%rbp,%rax,8)
ff
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1233 <main+0xc3>
movl   $0x0,-0x438(%rbp)
cmpl   $0x80,-0x438(%rbp)
jge    1326 <main+0x1b6>
movslq -0x438(%rbp),%rax
cmpq   $0x0,-0x430(%rbp,%rax,8)
jg     12d6 <main+0x166>
jmp    1312 <main+0x1a2>
mov    -0x2c(%rbp),%edi
mov    -0x438(%rbp),%esi
call   1030 <init_adt74x0@plt>
mov    %eax,-0x43c(%rbp)
cmpl   $0x0,-0x43c(%rbp)
jge    130d <main+0x19d>
movslq -0x43c(%rbp),%rcx
movslq -0x438(%rbp),%rax
mov    %rcx,-0x430(%rbp,%rax,8)
ff
jmp    1312 <main+0x1a2>
mov    -0x438(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x438(%rbp)
jmp    12ab <main+0x13b>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
movl   $0x0,-0x440(%rbp)
cmpl   $0x80,-0x440(%rbp)
jge    13e1 <main+0x271>
movslq -0x440(%rbp),%rax
cmpq   $0x0,-0x430(%rbp,%rax,8)
jg     1365 <main+0x1f5>
jmp    13cd <main+0x25d>
mov    -0x2c(%rbp),%edi
mov    -0x440(%rbp),%esi
lea    -0x448(%rbp),%rdx
call   1060 <read_adt74x0@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0x0,-0x44c(%rbp)
jge    13ac <main+0x23c>
mov    -0x440(%rbp),%esi
mov    -0x44c(%rbp),%edx
lea    0xc9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13c8 <main+0x258>
mov    -0x440(%rbp),%esi
movsd  -0x448(%rbp),%xmm0
ff
lea    0xc8e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    13cd <main+0x25d>
mov    -0x440(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x440(%rbp)
jmp    133a <main+0x1ca>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
movabs $0x6332692f7665642f,%rax
69 32 63
mov    %rax,0x8(%rsp)
movl   $0x302d63,0xf(%rsp)
cmp    $0x2,%edi
jl     11a1 <main+0x31>
mov    0x8(%rsi),%rbx
jmp    11a6 <main+0x36>
lea    0x8(%rsp),%rbx
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     12c0 <main+0x150>
mov    %eax,%ebp
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ecx,%ecx
cmp    $0x48,%rax
sete   %cl
mov    %rcx,0x20(%rsp,%rax,8)
mov    %rcx,0x28(%rsp,%rax,8)
mov    %rcx,0x30(%rsp,%rax,8)
mov    %rcx,0x38(%rsp,%rax,8)
add    $0x4,%rax
cmp    $0x80,%rax
jne    11e0 <main+0x70>
xor    %ebx,%ebx
jmp    121d <main+0xad>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x80,%rbx
je     123b <main+0xcb>
cmpq   $0x0,0x20(%rsp,%rbx,8)
jle    1210 <main+0xa0>
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <init_adt74x0@plt>
test   %eax,%eax
jns    1210 <main+0xa0>
cltq
mov    %rax,0x20(%rsp,%rbx,8)
jmp    1210 <main+0xa0>
mov    $0xf4240,%edi
call   1090 <usleep@plt>
lea    0x18(%rsp),%r14
lea    0xdeb(%rip),%r15
lea    0xdf7(%rip),%r12
xor    %ebx,%ebx
jmp    127f <main+0x10f>
nopl   0x0(%rax)
movsd  0x18(%rsp),%xmm0
mov    %r12,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x80,%rbx
je     12a7 <main+0x137>
cmpq   $0x0,0x20(%rsp,%rbx,8)
jle    1272 <main+0x102>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1060 <read_adt74x0@plt>
test   %eax,%eax
jns    1260 <main+0xf0>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1272 <main+0x102>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd62(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.default_file = [11 x i8] c"/dev/i2c-0\00"
@.str = [30 x i8] c"# Scanning %s for ADT74x0...\0A\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
@.str.2 = [19 x i8] c"# 0x%02x error %d\0A\00"
@.str.3 = [14 x i8] c"0x%02x %.5fC\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [11 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [128 x i64]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [11 x i8]* %6 to i8*
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
br label %25
23: ; preds = %2
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
br label %25
25: ; preds = %23, %19
%26 = phi i8* [ %22, %19 ], [ %24, %23 ]
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %7
%30 = load i32, i32* @O_RDWR
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = load i8*, i8** %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
store i32 0, i32* %10
br label %39
39: ; preds = %56, %38
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 128
br i1 %41, label %42, label %59
42: ; preds = %39
%43 = load i32, i32* %10
%44 = icmp sge i32 %43, 72
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* %10
%47 = icmp sle i32 %46, 75
br label %48
48: ; preds = %45, %42
%49 = phi i1 [ false, %42 ], [ %47, %45 ]
%50 = zext i1 %49 to i64
%51 = select i1 %49, i32 1, i32 0
%52 = sext i32 %51 to i64
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [128 x i64], [128 x i64]* %9, i64 0, i64 %54
store i64 %52, i64* %55
br label %56
56: ; preds = %48
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %39
59: ; preds = %39
store i32 0, i32* %11
br label %60
60: ; preds = %83, %59
%61 = load i32, i32* %11
%62 = icmp slt i32 %61, 128
br i1 %62, label %63, label %86
63: ; preds = %60
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [128 x i64], [128 x i64]* %9, i64 0, i64 %65
%67 = load i64, i64* %66
%68 = icmp sle i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %63
br label %83
70: ; preds = %63
%71 = load i32, i32* %8
%72 = load i32, i32* %11
%73 = call i32 @init_adt74x0(i32 %71, i32 %72)
store i32 %73, i32* %12
%74 = load i32, i32* %12
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %82
76: ; preds = %70
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = load i32, i32* %11
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [128 x i64], [128 x i64]* %9, i64 0, i64 %80
store i64 %78, i64* %81
br label %82
82: ; preds = %76, %70
br label %83
83: ; preds = %82, %69
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %60
86: ; preds = %60
%87 = call i32 @usleep(i32 1000000)
store i32 0, i32* %13
br label %88
88: ; preds = %113, %86
%89 = load i32, i32* %13
%90 = icmp slt i32 %89, 128
br i1 %90, label %91, label %116
91: ; preds = %88
%92 = load i32, i32* %13
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [128 x i64], [128 x i64]* %9, i64 0, i64 %93
%95 = load i64, i64* %94
%96 = icmp sle i64 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %91
br label %113
98: ; preds = %91
%99 = load i32, i32* %8
%100 = load i32, i32* %13
%101 = call i32 @read_adt74x0(i32 %99, i32 %100, double* %14)
store i32 %101, i32* %15
%102 = load i32, i32* %15
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %98
%105 = load i32, i32* %13
%106 = load i32, i32* %15
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %105, i32 %106)
br label %112
108: ; preds = %98
%109 = load i32, i32* %13
%110 = load double, double* %14
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %109, double %110)
br label %112
112: ; preds = %108, %104
br label %113
113: ; preds = %112, %97
%114 = load i32, i32* %13
%115 = add nsw i32 %114, 1
store i32 %115, i32* %13
br label %88
116: ; preds = %88
%117 = load i32, i32* %8
%118 = call i32 @close(i32 %117)
ret i32 0
}

LLVM IR (-O2):
@__const.main.default_file = [11 x i8] c"/dev/i2c-0\00"
@.str = [30 x i8] c"# Scanning %s for ADT74x0...\0A\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"Unable to open %s\0A\00"
@.str.2 = [19 x i8] c"# 0x%02x error %d\0A\00"
@.str.3 = [14 x i8] c"0x%02x %.5fC\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [11 x i8]
%4 = alloca [128 x i64]
%5 = alloca double
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
br label %11
11: ; preds = %2, %8
%12 = phi i8* [ %10, %8 ], [ %6, %2 ]
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* %12, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = bitcast [128 x i64]* %4 to i8*
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ 0, %20 ], [ %42, %22 ]
%24 = icmp eq i64 %23, 72
%25 = zext i1 %24 to i64
%26 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %23
store i64 %25, i64* %26
%27 = or i64 %23, 1
%28 = and i64 %23, 2147483644
%29 = icmp eq i64 %28, 72
%30 = zext i1 %29 to i64
%31 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %27
store i64 %30, i64* %31
%32 = or i64 %23, 2
%33 = and i64 %23, 2147483644
%34 = icmp eq i64 %33, 72
%35 = zext i1 %34 to i64
%36 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %32
store i64 %35, i64* %36
%37 = or i64 %23, 3
%38 = and i64 %23, 2147483644
%39 = icmp eq i64 %38, 72
%40 = zext i1 %39 to i64
%41 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %37
store i64 %40, i64* %41
%42 = add nuw nsw i64 %23, 4
%43 = icmp eq i64 %42, 128
br i1 %43, label %47, label %22
44: ; preds = %58
%45 = call i32 @usleep(i32 1000000)
%46 = bitcast double* %5 to i8*
br label %63
47: ; preds = %22, %58
%48 = phi i64 [ %59, %58 ], [ 0, %22 ]
%49 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %48
%50 = load i64, i64* %49
%51 = icmp slt i64 %50, 1
br i1 %51, label %58, label %52
52: ; preds = %47
%53 = trunc i64 %48 to i32
%54 = call i32 @init_adt74x0(i32 %15, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = sext i32 %54 to i64
store i64 %57, i64* %49
br label %58
58: ; preds = %52, %56, %47
%59 = add nuw nsw i64 %48, 1
%60 = icmp eq i64 %59, 128
br i1 %60, label %44, label %47
61: ; preds = %78
%62 = call i32 @close(i32 %15)
ret i32 0
63: ; preds = %44, %78
%64 = phi i64 [ 0, %44 ], [ %79, %78 ]
%65 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 %64
%66 = load i64, i64* %65
%67 = icmp slt i64 %66, 1
br i1 %67, label %78, label %68
68: ; preds = %63
%69 = trunc i64 %64 to i32
%70 = call i32 @read_adt74x0(i32 %15, i32 %69, double* %5)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %69, i32 %70)
br label %77
74: ; preds = %68
%75 = load double, double* %5
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %69, double %75)
br label %77
77: ; preds = %74, %72
br label %78
78: ; preds = %63, %77
%79 = add nuw nsw i64 %64, 1
%80 = icmp eq i64 %79, 128
br i1 %80, label %61, label %63
}