#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 /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ Buf;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main() {
  FILE *fp0 = NULL;
  char Buf[4096];
  fp0 = fopen("/dev/ds18b20", "r+");
  if (fp0 == NULL) {
    printf("Open Temperature Device Error!\n");
    return -1;
  }
  while (1) {
    usleep(500 * 1000);
    fread(Buf, sizeof(Buf), 2, fp0);
    printf("\n Temperature =%d.%02d\n", Buf[0], Buf[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe9f(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <main+0x58>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x1010,%rsp
pop    %rbp
ret
jmp    119d <main+0x5d>
mov    $0x7a120,%edi
call   1060 <usleep@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1000,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
movsbl -0x1010(%rbp),%esi
movsbl -0x100f(%rbp),%edx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119d <main+0x5d>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c4 <main+0x74>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe8f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x7a120,%edi
call   1070 <usleep@plt>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movsbl (%rsp),%esi
movsbl 0x1(%rsp),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1190 <main+0x40>
lea    0xe5d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ds18b20\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [32 x i8] c"Open Temperature Device Error!\0A\00"
@.str.3 = [24 x i8] c"\0A Temperature =%d.%02d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4096 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
ret i32 -1
9: ; preds = %0
br label %10
10: ; preds = %9, %10
%11 = call i32 @usleep(i32 500000)
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %2
%14 = call i32 @fread(i8* %12, i32 4096, i32 2, i32* %13)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 %20)
br label %10
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ds18b20\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.3 = [24 x i8] c"\0A Temperature =%d.%02d\0A\00"
@str = [31 x i8] c"Open Temperature Device Error!\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 1
br label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
ret i32 -1
9: ; preds = %5, %9
%10 = tail call i32 @usleep(i32 500000)
%11 = call i32 @fread(i8* %2, i32 4096, i32 2, i32* %3)
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %15)
br label %9
}