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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int readHcsr04() {
  FILE *o;
  int x;
  int us;
  if ((o = fopen("/sys/class/hcsr04/value", "r")) != NULL) {
    fscanf(o, "%d", &x);
    us = x;
    fclose(o);
  } else {
    printf("\n\rError read hcsr04\n\r");
    exit(-1);
  }
  return us;
}


x86 assembly (clang, -O0):
<readHcsr04>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11a1 <readHcsr04+0x51>
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11b7 <readHcsr04+0x67>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readHcsr04>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1197 <readHcsr04+0x47>
mov    %rax,%rbx
lea    0xea5(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0x4(%rsp),%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"/sys/class/hcsr04/value\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"\0A\0DError read hcsr04\0A\0D\00"
define i32 @readHcsr04() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32*, i32** %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
store i32 %9, i32* %3
%10 = load i32*, i32** %1
%11 = call i32 @fclose(i32* %10)
br label %15
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %6
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
@.str = [24 x i8] c"/sys/class/hcsr04/value\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"\0A\0DError read hcsr04\0A\0D\00"
define i32 @readHcsr04() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @fclose(i32* %3)
ret i32 %7
9: ; preds = %0
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
}