#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*/ buf;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int read_analog_device_value(int device_file) {
  char buf[1024];
  int a_err = -1;
  int ret = read(device_file, buf, sizeof(buf));
  if (ret == a_err) {
    printf("Couldn't get value from Analog Pin\n");
    return -1;
  }
  buf[ret] = '\0';
  lseek(device_file, 0, 0);
  return atoi(buf);
}


x86 assembly (clang, -O0):
<read_analog_device_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
jne    119c <read_analog_device_value+0x5c>
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <read_analog_device_value+0x86>
movslq -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <lseek@plt>
lea    -0x410(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_analog_device_value>:
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1177 <read_analog_device_value+0x37>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    %rsp,%rdi
call   1060 <atoi@plt>
jmp    1188 <read_analog_device_value+0x48>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Couldn't get value from Analog Pin\0A\00"
define i32 @read_analog_device_value(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 -1, i32* %5
%7 = load i32, i32* %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 1024)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %23
15: ; preds = %1
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* %3
%20 = call i32 @lseek(i32 %19, i32 0, i32 0)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %15, %13
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@str = [35 x i8] c"Couldn't get value from Analog Pin\00"
define i32 @read_analog_device_value(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1024)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = sext i32 %4 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = tail call i32 @lseek(i32 %0, i32 0, i32 0)
%12 = call i32 @atoi(i8* %3)
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ -1, %6 ], [ %12, %8 ]
ret i32 %14
}