#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *,
                           char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ truncate_newline(char *);
int main(void) {
  FILE *file;
  file = fopen("name.txt", "w+");
  printf("Please enter your name: ");
  char name[80];
  fgets(name, 80, stdin);
  truncate_newline(name);
  printf("Please enter your age: ");
  char age[80];
  fgets(age, 80, stdin);
  truncate_newline(age);
  printf("Please enter your username: ");
  char username[80];
  fgets(username, 80, stdin);
  truncate_newline(username);
  fprintf(file,
          "Your name is %s, you are %s years old, and your username is %s.\n",
          name, age, username);
  rewind(file);
  for (;;) {
    int c = fgetc(file);
    if (feof(file)) {
      break;
    }
    printf("%c", c);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe59(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1070 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   10a0 <truncate_newline@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1070 <fgets@plt>
lea    -0xb0(%rbp),%rdi
call   10a0 <truncate_newline@plt>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1070 <fgets@plt>
lea    -0x100(%rbp),%rdi
call   10a0 <truncate_newline@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    -0xb0(%rbp),%rcx
lea    -0x100(%rbp),%r8
lea    0xdee(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x104(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     12a1 <main+0x111>
jmp    12ba <main+0x12a>
mov    -0x104(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127a <main+0xea>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xf8,%rsp
lea    0xe4c(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0xa0(%rsp),%r14
mov    %r14,%rdi
mov    $0x50,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
call   10b0 <truncate_newline@plt>
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
lea    0x50(%rsp),%r15
mov    %r15,%rdi
mov    $0x50,%esi
call   1080 <fgets@plt>
mov    %r15,%rdi
call   10b0 <truncate_newline@plt>
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x50,%esi
call   1080 <fgets@plt>
mov    %rbp,%rdi
call   10b0 <truncate_newline@plt>
lea    0xe07(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbp,%r8
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <rewind@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
jne    1290 <main+0xf0>
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    1270 <main+0xd0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"name.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [25 x i8] c"Please enter your name: \00"
@stdin = global i32 0
@.str.3 = [24 x i8] c"Please enter your age: \00"
@.str.4 = [29 x i8] c"Please enter your username: \00"
@.str.5 = [65 x i8] c"Your name is %s, you are %s years old, and your username is %s.\0A\00"
@.str.6 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 80, i32 %10)
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = call i32 @truncate_newline(i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 80, i32 %16)
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%19 = call i32 @truncate_newline(i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* %21, i32 80, i32 %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%25 = call i32 @truncate_newline(i8* %24)
%26 = load i32*, i32** %2
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%30 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i8* %27, i8* %28, i8* %29)
%31 = load i32*, i32** %2
%32 = call i32 @rewind(i32* %31)
br label %33
33: ; preds = %40, %0
%34 = load i32*, i32** %2
%35 = call i32 @fgetc(i32* %34)
store i32 %35, i32* %6
%36 = load i32*, i32** %2
%37 = call i64 @feof(i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
br label %43
40: ; preds = %33
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %41)
br label %33
43: ; preds = %39
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"name.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [25 x i8] c"Please enter your name: \00"
@stdin = global i32 0
@.str.3 = [24 x i8] c"Please enter your age: \00"
@.str.4 = [29 x i8] c"Please enter your username: \00"
@.str.5 = [65 x i8] c"Your name is %s, you are %s years old, and your username is %s.\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 80, i32 %7)
%9 = call i32 @truncate_newline(i8* %6)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 80, i32 %12)
%14 = call i32 @truncate_newline(i8* %11)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 80, i32 %17)
%19 = call i32 @truncate_newline(i8* %16)
%20 = call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.5, i64 0, i64 0), i8* %6, i8* %11, i8* %16)
%21 = call i32 @rewind(i32* %4)
%22 = call i32 @fgetc(i32* %4)
%23 = call i64 @feof(i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %0, %25
%26 = phi i32 [ %28, %25 ], [ %22, %0 ]
%27 = call i32 @putchar(i32 %26)
%28 = call i32 @fgetc(i32* %4)
%29 = call i64 @feof(i32* %4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %25, label %31
31: ; preds = %25, %0
%32 = call i32 @fclose(i32* %4)
ret i32 0
}