#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 st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int fileno(int /*<<< orphan*/ *);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int GCONV_get_file_size(FILE *fp) {
  struct stat st;
  int fd;
  fd = fileno(fp);
  if (fstat(fd, &st)) {
    printf("\nfstat error: [%s]\n", strerror(errno));
    return -1;
  }
  return st.st_size;
}


x86 assembly (clang, -O0):
<GCONV_get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <fstat@plt>
cmp    $0x0,%rax
je     1197 <GCONV_get_file_size+0x57>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <GCONV_get_file_size+0x5d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GCONV_get_file_size>:
push   %rax
call   1040 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1060 <fstat@plt>
test   %rax,%rax
je     1179 <GCONV_get_file_size+0x39>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe96(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"\0Afstat error: [%s]\0A\00"
@errno = global i32 0
define i32 @GCONV_get_file_size(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca %struct.stat
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @fileno(i32* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = call i64 @fstat(i32 %8, %struct.stat* %4)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 -1, i32* %2
br label %18
15: ; preds = %1
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%17 = load i32, i32* %16
store i32 %17, i32* %2
br label %18
18: ; preds = %15, %11
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"\0Afstat error: [%s]\0A\00"
@errno = global i32 0
define i32 @GCONV_get_file_size(i32* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32 @fileno(i32* %0)
%5 = call i64 @fstat(i32 %4, %struct.stat* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %14
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ -1, %7 ], [ %13, %11 ]
ret i32 %15
}