#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int Sys_FileSize(char *fname) {
  int len;
  FILE *f;
  if (!strncmp(fname, "src/", 4))
    fname += 4;
  f = fopen(fname, "rb");
  if (!f)
    return -1;
  fseek(f, 0, SEEK_END);
  len = ftell(f);
  fclose(f);
  return len;
}


x86 assembly (clang, -O0):
<Sys_FileSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1186 <Sys_FileSize+0x36>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <Sys_FileSize+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e0 <Sys_FileSize+0x90>
mov    -0x20(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sys_FileSize>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea3(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rbx,%rcx,4),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11af <Sys_FileSize+0x5f>
mov    %rax,%rbx
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
jmp    11b4 <Sys_FileSize+0x64>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"src/\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @Sys_FileSize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 4
store i8* %11, i8** %3
br label %12
12: ; preds = %9, %1
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 -1, i32* %2
br label %27
18: ; preds = %12
%19 = load i32*, i32** %5
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %5
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %4
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %18, %17
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [5 x i8] c"src/\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @Sys_FileSize(i8* %0) {
%2 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i64 4, i64 0
%5 = getelementptr i8, i8* %0, i64 %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %6, i32 0, i32 %9)
%11 = tail call i32 @ftell(i32* %6)
%12 = tail call i32 @fclose(i32* %6)
br label %13
13: ; preds = %1, %8
%14 = phi i32 [ %11, %8 ], [ -1, %1 ]
ret i32 %14
}