#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*/ reddit_username;
typedef int /*<<< orphan*/ name;
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 *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int main(void) {
  char name[256];
  char reddit_username[256];
  int age;
  char resulting_string[1024];
  char temp;
  FILE *fp;
  printf("What is your name? ");
  if (fgets(name, sizeof(name), stdin) != NULL) {
    char *pos;
    if ((pos = strchr(name, '\n')) != NULL)
      *pos = '\0';
  }
  printf("What is your age? ");
  scanf("%i", &age);
  scanf("%c", &temp);
  printf("What is your reddit username? ");
  if (fgets(reddit_username, sizeof(reddit_username), stdin) != NULL) {
    char *pos;
    if ((pos = strchr(reddit_username, '\n')) != NULL)
      *pos = '\0';
  }
  sprintf(resulting_string,
          "Your name is %s, you are %d years old and your username is %s\n",
          name, age, reddit_username);
  printf(resulting_string);
  fp = fopen("log.txt", "w+");
  fprintf(fp, resulting_string);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11f3 <main+0x73>
lea    -0x110(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x638(%rbp)
cmp    $0x0,%rax
je     11ee <main+0x6e>
mov    -0x638(%rbp),%rax
movb   $0x0,(%rax)
jmp    11f3 <main+0x73>
lea    0xe1a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe21(%rip),%rdi
lea    -0x214(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xe0f(%rip),%rdi
lea    -0x621(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xdfd(%rip),%rdi
call   1050 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     128a <main+0x10a>
lea    -0x210(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x640(%rbp)
cmp    $0x0,%rax
je     1285 <main+0x105>
mov    -0x640(%rbp),%rax
movb   $0x0,(%rax)
jmp    128a <main+0x10a>
lea    -0x620(%rbp),%rdi
lea    -0x110(%rbp),%rdx
mov    -0x214(%rbp),%ecx
lea    -0x210(%rbp),%r8
lea    0xda0(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x620(%rbp),%rdi
call   1050 <printf@plt>
lea    0xdc7(%rip),%rdi
lea    0xdc8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x630(%rbp)
mov    -0x630(%rbp),%rdi
lea    -0x620(%rbp),%rsi
call   1070 <fprintf@plt>
mov    -0x630(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x618,%rsp
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e4b(%rip),%rbx
mov    (%rbx),%edx
lea    0x110(%rsp),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11d0 <main+0x50>
lea    0x110(%rsp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d0 <main+0x50>
movb   $0x0,(%rax)
lea    0xe3d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe44(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe34(%rip),%rdi
lea    0xb(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
mov    (%rbx),%edx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     123b <main+0xbb>
lea    0x10(%rsp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     123b <main+0xbb>
movb   $0x0,(%rax)
mov    0xc(%rsp),%ecx
lea    0xe06(%rip),%rsi
lea    0x210(%rsp),%r14
lea    0x110(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    %r14,%rdi
call   10a0 <sprintf@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
lea    0xe19(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"What is your name? \00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"What is your age? \00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [31 x i8] c"What is your reddit username? \00"
@.str.5 = [63 x i8] c"Your name is %s, you are %d years old and your username is %s\0A\00"
@.str.6 = [8 x i8] c"log.txt\00"
@.str.7 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32* @fgets(i8* %11, i32 256, i32 %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %22
15: ; preds = %0
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i8* @strchr(i8* %16, i8 signext 10)
store i8* %17, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i8*, i8** %8
store i8 0, i8* %20
br label %21
21: ; preds = %19, %15
br label %22
22: ; preds = %21, %0
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%25 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%26 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = load i32, i32* @stdin
%29 = call i32* @fgets(i8* %27, i32 256, i32 %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %38
31: ; preds = %22
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = call i8* @strchr(i8* %32, i8 signext 10)
store i8* %33, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = load i8*, i8** %9
store i8 0, i8* %36
br label %37
37: ; preds = %35, %31
br label %38
38: ; preds = %37, %22
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%41 = load i32, i32* %4
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%43 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0), i8* %40, i32 %41, i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%45 = call i32 @printf(i8* %44)
%46 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %46, i32** %7
%47 = load i32*, i32** %7
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%49 = call i32 @fprintf(i32* %47, i8* %48)
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"What is your name? \00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"What is your age? \00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [31 x i8] c"What is your reddit username? \00"
@.str.5 = [63 x i8] c"Your name is %s, you are %d years old and your username is %s\0A\00"
@.str.6 = [8 x i8] c"log.txt\00"
@.str.7 = [3 x i8] c"w+\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i8
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32* @fgets(i8* %6, i32 256, i32 %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %0
%15 = call i8* @strchr(i8* %6, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8 0, i8* %15
br label %18
18: ; preds = %14, %17, %0
%19 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* @stdin
%24 = call i32* @fgets(i8* %7, i32 256, i32 %23)
%25 = icmp eq i32* %24, null
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = call i8* @strchr(i8* %7, i8 signext 10)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i8 0, i8* %27
br label %30
30: ; preds = %26, %29, %18
%31 = load i32, i32* %3
%32 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 %31, i8* %7)
%33 = call i32 @printf(i8* %9)
%34 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 @fprintf(i32* %34, i8* %9)
%36 = call i32 @fclose(i32* %34)
ret i32 0
}