#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *);
int readGyro(void) {
  FILE *pin = NULL;
  int reading = -1;
  if ((pin = fopen("/sys/devices/platform/omap/tsc/ain3", "r")) == NULL)
    printf("Can't open ain3\n");
  else {
    fscanf(pin, "%d", &reading);
    fclose(pin);
  }
  return reading;
}


x86 assembly (clang, -O0):
<readGyro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    0xea2(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1189 <readGyro+0x49>
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
jmp    11a6 <readGyro+0x66>
mov    -0x8(%rbp),%rdi
lea    0xea3(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readGyro>:
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xeac(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     118a <readGyro+0x4a>
mov    %rax,%rbx
lea    0xeb7(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    119b <readGyro+0x5b>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/devices/platform/omap/tsc/ain3\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Can't open ain3\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @readGyro() {
%1 = alloca i32*
%2 = alloca i32
store i32* null, i32** %1
store i32 -1, i32* %2
%3 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %12
7: ; preds = %0
%8 = load i32*, i32** %1
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%10 = load i32*, i32** %1
%11 = call i32 @fclose(i32* %10)
br label %12
12: ; preds = %7, %5
%13 = load i32, i32* %2
ret i32 %13
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/devices/platform/omap/tsc/ain3\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [16 x i8] c"Can't open ain3\00"
define i32 @readGyro() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 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 %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %11
7: ; preds = %0
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = call i32 @fclose(i32* %3)
%10 = load i32, i32* %1
br label %11
11: ; preds = %7, %5
%12 = phi i32 [ %10, %7 ], [ -1, %5 ]
ret i32 %12
}