#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
int main() {
  FILE *fp;
  char name[255];
  fp = fopen("Cow", "w+");
  printf("What's your name?\n");
  fgets(name, 254, stdin);
  fprintf(fp, "Hello! I'm %s", name);
  fclose(fp);
  system("xcowsay < Cow");
  system("rm Cow");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb5(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe73(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
mov    $0xfe,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe4e(%rip),%rdi
call   1040 <system@plt>
lea    0xe50(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xeaa(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xfe,%esi
call   1060 <fgets@plt>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe4b(%rip),%rdi
call   1050 <system@plt>
lea    0xe4d(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"Cow\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [19 x i8] c"What's your name?\0A\00"
@stdin = global i32 0
@.str.3 = [14 x i8] c"Hello! I'm %s\00"
@.str.4 = [14 x i8] c"xcowsay < Cow\00"
@.str.5 = [7 x i8] c"rm Cow\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [255 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 254, i32 %7)
%9 = load i32*, i32** %2
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%11 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
%14 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"Cow\00"
@.str.1 = [3 x i8] c"w+\00"
@stdin = global i32 0
@.str.3 = [14 x i8] c"Hello! I'm %s\00"
@.str.4 = [14 x i8] c"xcowsay < Cow\00"
@.str.5 = [7 x i8] c"rm Cow\00"
@str = [18 x i8] c"What's your name?\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 254, i32 %5)
%7 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%8 = call i32 @fclose(i32* %3)
%9 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}