#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*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ replaceNewLine(char *);
int /*<<< orphan*/ stdout;
int getStat(const char *cmd) {
  char source[10000 + 1];
  FILE *proc;
  proc = fopen(cmd, "r");
  if (proc) {
    size_t newLen = fread(source, sizeof(char), 10000, proc);
    source[newLen++] = ';';
    source[newLen] = '\0';
    replaceNewLine(source);
    fwrite(source, sizeof(char), newLen, stdout);
    fclose(proc);
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<getStat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x2738(%rbp)
cmpq   $0x0,-0x2738(%rbp)
je     1219 <getStat+0xc9>
lea    -0x2730(%rbp),%rdi
mov    -0x2738(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2710,%edx
call   1030 <fread@plt>
mov    %rax,-0x2740(%rbp)
mov    -0x2740(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x2740(%rbp)
movb   $0x3b,-0x2730(%rbp,%rax,1)
3b
mov    -0x2740(%rbp),%rax
movb   $0x0,-0x2730(%rbp,%rax,1)
lea    -0x2730(%rbp),%rdi
call   1050 <replaceNewLine@plt>
lea    -0x2730(%rbp),%rdi
mov    -0x2740(%rbp),%rdx
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x2738(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1220 <getStat+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2718,%rsp
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c4 <getStat+0x74>
mov    %rax,%rbx
mov    %rsp,%r14
mov    $0x1,%r15d
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x2710,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
movw   $0x3b,(%rsp,%rax,1)
lea    0x1(%rax),%rbp
mov    %r14,%rdi
call   1050 <replaceNewLine@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11c7 <getStat+0x77>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @getStat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [10001 x i8]
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %28
11: ; preds = %1
%12 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i64 @fread(i8* %12, i32 1, i32 10000, i32* %13)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = add i64 %15, 1
store i64 %16, i64* %6
%17 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 %15
store i8 59, i8* %17
%18 = load i64, i64* %6
%19 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 0
%21 = call i32 @replaceNewLine(i8* %20)
%22 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 0
%23 = load i64, i64* %6
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %22, i32 1, i64 %23, i32 %24)
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
store i32 1, i32* %2
br label %29
28: ; preds = %1
store i32 0, i32* %2
br label %29
29: ; preds = %28, %11
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @getStat(i8* nocapture %0) {
%2 = alloca [10001 x i8]
%3 = getelementptr inbounds [10001 x i8], [10001 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = call i64 @fread(i8* %3, i32 1, i32 10000, i32* %4)
%8 = add i64 %7, 1
%9 = getelementptr inbounds [10001 x i8], [10001 x i8]* %2, i64 0, i64 %7
store i8 59, i8* %9
%10 = getelementptr inbounds [10001 x i8], [10001 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %10
%11 = call i32 @replaceNewLine(i8* %3)
%12 = load i32, i32* @stdout
%13 = call i32 @fwrite(i8* %3, i32 1, i64 %8, i32 %12)
%14 = call i32 @fclose(i32* %4)
br label %15
15: ; preds = %1, %6
%16 = phi i32 [ 1, %6 ], [ 0, %1 ]
ret i32 %16
}