#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int fsize(const char *fname) {
  FILE *fp;
  long the_size;
  if ((fp = fopen(fname, "rb")) == NULL) {
    printf("Error opening %s.\n", fname);
  }
  do {
    getc(fp);
  } while (!feof(fp));
  the_size = ftell(fp);
  fclose(fp);
  return the_size;
}


x86 assembly (clang, -O0):
<fsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119a <fsize+0x3a>
mov    -0x8(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
jmp    119f <fsize+0x3f>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119f <fsize+0x3f>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsize>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <fsize+0x30>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1190 <fsize+0x30>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [19 x i8] c"Error opening %s.\0A\00"
define i32 @fsize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %1
br label %12
12: ; preds = %15, %11
%13 = load i32*, i32** %3
%14 = call i32 @getc(i32* %13)
br label %15
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %12, label %20
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = call i64 @ftell(i32* %21)
store i64 %22, i64* %4
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i64, i64* %4
%26 = trunc i64 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [19 x i8] c"Error opening %s.\0A\00"
define i32 @fsize(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %1
br label %7
7: ; preds = %6, %7
%8 = tail call i32 @getc(i32* %2)
%9 = tail call i32 @feof(i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %7, label %11
11: ; preds = %7
%12 = tail call i64 @ftell(i32* %2)
%13 = tail call i32 @fclose(i32* %2)
%14 = trunc i64 %12 to i32
ret i32 %14
}