#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 */

/* Variables and functions */
unsigned long atol(char *);
char *pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
unsigned long get_file_size(char *filename) {
  char sys_string[1024];
  char *results_string;
  sprintf(sys_string,
          "echo '%s'				|"
          "stat.e				|"
          "grep \"\\.size \"			|"
          "column.e 1				 ",
          filename);
  results_string = pipe2string(sys_string);
  if (!results_string)
    return 0;
  else
    return atol(results_string);
}


x86 assembly (clang, -O0):
<get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaf(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1030 <pipe2string@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1184 <get_file_size+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1194 <get_file_size+0x64>
mov    -0x418(%rbp),%rdi
call   1040 <atol@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_size>:
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rdx
lea    0xebe(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <pipe2string@plt>
test   %rax,%rax
je     1164 <get_file_size+0x34>
mov    %rax,%rdi
call   1040 <atol@plt>
jmp    1166 <get_file_size+0x36>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [59 x i8] c"echo '%s'\09\09\09\09|stat.e\09\09\09\09|grep \22\\.size \22\09\09\09|column.e 1\09\09\09\09 \00"
define i64 @get_file_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i8* @pipe2string(i8* %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
store i64 0, i64* %2
br label %17
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = call i64 @atol(i8* %15)
store i64 %16, i64* %2
br label %17
17: ; preds = %14, %13
%18 = load i64, i64* %2
ret i64 %18
}

LLVM IR (-O2):
@.str = [59 x i8] c"echo '%s'\09\09\09\09|stat.e\09\09\09\09|grep \22\\.size \22\09\09\09|column.e 1\09\09\09\09 \00"
define i64 @get_file_size(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i8* @pipe2string(i8* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i64 @atol(i8* %5)
br label %9
9: ; preds = %1, %7
%10 = phi i64 [ %8, %7 ], [ 0, %1 ]
ret i64 %10
}