#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 /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
unsigned long long strtoull(char *, char **, int /*<<< orphan*/);
int sysfs_fd_get_ll(int fd, unsigned long long *val) {
  char buf[50];
  int n;
  char *ep;
  lseek(fd, 0, 0);
  n = read(fd, buf, sizeof(buf));
  if (n <= 0)
    return -2;
  buf[n] = 0;
  *val = strtoull(buf, &ep, 0);
  if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<sysfs_fd_get_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1040 <read@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jg     1175 <sysfs_fd_get_ll+0x45>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11eb <sysfs_fd_get_ll+0xbb>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoull@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
cmp    %rcx,%rax
je     11d8 <sysfs_fd_get_ll+0xa8>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e4 <sysfs_fd_get_ll+0xb4>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11e4 <sysfs_fd_get_ll+0xb4>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11e4 <sysfs_fd_get_ll+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11eb <sysfs_fd_get_ll+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_fd_get_ll>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
xor    %esi,%esi
xor    %edx,%edx
call   1030 <lseek@plt>
lea    0x10(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x32,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11a3 <sysfs_fd_get_ll+0x73>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtoull@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rcx
mov    $0xffffffff,%eax
cmp    %rbx,%rcx
je     11a8 <sysfs_fd_get_ll+0x78>
movzbl (%rcx),%ecx
cmp    $0x20,%rcx
ja     11a8 <sysfs_fd_get_ll+0x78>
movabs $0x100000401,%rdx
bt     %rcx,%rdx
jae    11a8 <sysfs_fd_get_ll+0x78>
xor    %eax,%eax
jmp    11a8 <sysfs_fd_get_ll+0x78>
mov    $0xfffffffe,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sysfs_fd_get_ll(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca [50 x i8]
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i64* %1, i64** %5
%9 = load i32, i32* %4
%10 = call i32 @lseek(i32 %9, i32 0, i32 0)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 50)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -2, i32* %3
br label %44
17: ; preds = %2
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%22 = call i64 @strtoull(i8* %21, i8** %8, i32 0)
%23 = load i64*, i64** %5
store i64 %22, i64* %23
%24 = load i8*, i8** %8
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%26 = icmp eq i8* %24, %25
br i1 %26, label %42, label %27
27: ; preds = %17
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i8*, i8** %8
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 32
br i1 %41, label %42, label %43
42: ; preds = %37, %17
store i32 -1, i32* %3
br label %44
43: ; preds = %37, %32, %27
store i32 0, i32* %3
br label %44
44: ; preds = %43, %42, %16
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @sysfs_fd_get_ll(i32 %0, i64* nocapture writeonly %1) {
%3 = alloca [50 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 @lseek(i32 %0, i32 0, i32 0)
%8 = call i32 @read(i32 %0, i8* %5, i32 50)
%9 = icmp slt i32 %8, 1
br i1 %9, label %19, label %10
10: ; preds = %2
%11 = zext i32 %8 to i64
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i64 @strtoull(i8* %5, i8** %4, i32 0)
store i64 %13, i64* %1
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, %5
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = load i8, i8* %14
switch i8 %17, label %19 [
i8 0, label %18
i8 10, label %18
i8 32, label %18
]
18: ; preds = %16, %16, %16
br label %19
19: ; preds = %10, %16, %2, %18
%20 = phi i32 [ 0, %18 ], [ -2, %2 ], [ -1, %16 ], [ -1, %10 ]
ret i32 %20
}