#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 {
  long st_size;
};

/* Variables and functions */
char *fm_abs(char *);
int /*<<< orphan*/ free(char *);
int stat(char *, struct stat *);
long fm_size(char *filename) {
  char *fa = NULL;
  struct stat s;
  fa = fm_abs(filename);
  if (stat(fa, &s) == -1)
    s.st_size = 0;
  do {
    if ((fa) != NULL) {
      free(fa);
      (fa) = NULL;
    }
  } while (0);
  return (s.st_size);
}


x86 assembly (clang, -O0):
<fm_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fm_abs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    116f <fm_size+0x3f>
movq   $0x0,-0x18(%rbp)
jmp    1174 <fm_size+0x44>
cmpq   $0x0,-0x10(%rbp)
je     1190 <fm_size+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
jmp    1195 <fm_size+0x65>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fm_size>:
push   %rbx
sub    $0x10,%rsp
call   1040 <fm_abs@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1167 <fm_size+0x37>
test   %rbx,%rbx
je     115c <fm_size+0x2c>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
movq   $0x0,0x8(%rsp)
test   %rbx,%rbx
jne    1154 <fm_size+0x24>
jmp    115c <fm_size+0x2c>

LLVM IR (-O0):
%struct.stat = type { i64 }
define i64 @fm_size(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %2
store i8* null, i8** %3
%5 = load i8*, i8** %2
%6 = call i8* @fm_abs(i8* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @stat(i8* %7, %struct.stat* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
store i64 0, i64* %11
br label %12
12: ; preds = %10, %1
br label %13
13: ; preds = %12
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = call i32 @free(i8* %17)
store i8* null, i8** %3
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i64, i64* %21
ret i64 %22
}

LLVM IR (-O2):
%struct.stat = type { i64 }
define i64 @fm_size(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i8* @fm_abs(i8* %0)
%5 = call i32 @stat(i8* %4, %struct.stat* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i64 0, i64* %8
br label %9
9: ; preds = %1, %7
%10 = icmp eq i8* %4, null
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @free(i8* %4)
br label %13
13: ; preds = %11, %9
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%15 = load i64, i64* %14
ret i64 %15
}