#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 */
struct stat {
  int dummy;
};
typedef scalar_t__ off_t;
typedef scalar_t__ ino_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ stat(char *, struct stat *);
char *strchr(char *, char);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int read_offset(char *filename, ino_t *inode, off_t *offset) {
  FILE *f;
  char buf[4096], *p;
  struct stat fs;
  *inode = 0;
  *offset = 0;
  if (stat(filename, &fs) < 0)
    return 0;
  if ((f = fopen(filename, "r")) == NULL)
    return errno;
  if (fgets(buf, 4096, f) == NULL)
    return errno;
  p = strchr(buf, ' ');
  *inode = (ino_t)strtol(buf, NULL, 10);
  *offset = (off_t)strtol(p + 1, NULL, 10);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<read_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11b3 <read_offset+0x53>
movl   $0x0,-0x4(%rbp)
jmp    127c <read_offset+0x11c>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e2 <read_offset+0x82>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <read_offset+0x11c>
lea    -0x1030(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1212 <read_offset+0xb2>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <read_offset+0x11c>
lea    -0x1030(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1038(%rbp)
lea    -0x1030(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1038(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     120f <read_offset+0xaf>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1213 <read_offset+0xb3>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1213 <read_offset+0xb3>
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,(%r12)
add    $0x1,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,(%r14)
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    121c <read_offset+0xbc>
xor    %ebx,%ebx
jmp    121c <read_offset+0xbc>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @read_offset(i8* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca [4096 x i8]
%10 = alloca i8*
%11 = alloca %struct.stat
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%12 = load i64*, i64** %6
store i64 0, i64* %12
%13 = load i64*, i64** %7
store i64 0, i64* %13
%14 = load i8*, i8** %5
%15 = call i64 @stat(i8* %14, %struct.stat* %11)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 0, i32* %4
br label %43
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %8
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i32, i32* @errno
store i32 %23, i32* %4
br label %43
24: ; preds = %18
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%26 = load i32*, i32** %8
%27 = call i32* @fgets(i8* %25, i32 4096, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = load i32, i32* @errno
store i32 %30, i32* %4
br label %43
31: ; preds = %24
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%33 = call i8* @strchr(i8* %32, i8 signext 32)
store i8* %33, i8** %10
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%35 = call i64 @strtol(i8* %34, i32* null, i32 10)
%36 = load i64*, i64** %6
store i64 %35, i64* %36
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i64 @strtol(i8* %38, i32* null, i32 10)
%40 = load i64*, i64** %7
store i64 %39, i64* %40
%41 = load i32*, i32** %8
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %4
br label %43
43: ; preds = %31, %29, %22, %17
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @read_offset(i8* %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca [4096 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.stat* %5 to i8*
store i64 0, i64* %1
store i64 0, i64* %2
%8 = call i64 @stat(i8* %0, %struct.stat* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %3
%11 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* @errno
br label %26
15: ; preds = %10
%16 = call i32* @fgets(i8* %6, i32 4096, i32* %11)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* @errno
br label %26
20: ; preds = %15
%21 = call i8* @strchr(i8* %6, i8 signext 32)
%22 = call i64 @strtol(i8* nocapture %6, i32* null, i32 10)
store i64 %22, i64* %1
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = call i64 @strtol(i8* nocapture %23, i32* null, i32 10)
store i64 %24, i64* %2
%25 = call i32 @fclose(i32* %11)
br label %26
26: ; preds = %3, %20, %18, %13
%27 = phi i32 [ %14, %13 ], [ %19, %18 ], [ 0, %20 ], [ 0, %3 ]
ret i32 %27
}