#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, int, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  char name[32];
  int age;
  char address[128];
  FILE *fp;
  fp = fopen("test.txt", "w");
  if (fp == NULL) {
    printf("Can't open file!\n");
    return -1;
  }
  printf("name: ");
  scanf("%s", name);
  printf("age: ");
  scanf("%d", &age);
  printf("address: ");
  scanf("%s", address);
  fprintf(fp, "%s %d %s", name, age, address);
  printf("Completed.\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
jne    11a2 <main+0x52>
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <main+0xef>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0xc8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%ecx
lea    -0xc0(%rbp),%r8
lea    0xe1c(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc8(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1222 <main+0xc2>
mov    %rax,%rbx
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
lea    0xe8a(%rip),%r15
xor    %r12d,%r12d
lea    0x10(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0xe3f(%rip),%rdi
call   1050 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%ecx
lea    0xe27(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %rbp,%r8
call   1060 <fprintf@plt>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1234 <main+0xd4>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [18 x i8] c"Can't open file!\0A\00"
@.str.3 = [7 x i8] c"name: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"age: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [10 x i8] c"address: \00"
@.str.8 = [9 x i8] c"%s %d %s\00"
@.str.9 = [12 x i8] c"Completed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %28
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %5
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%22 = load i32, i32* %3
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%24 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %21, i32 %22, i8* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
store i32 0, i32* %1
br label %28
28: ; preds = %11, %9
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"name: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"age: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [10 x i8] c"address: \00"
@.str.8 = [9 x i8] c"%s %d %s\00"
@str = [11 x i8] c"Completed.\00"
@str.10 = [17 x i8] c"Can't open file!\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
br label %22
11: ; preds = %0
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%18 = load i32, i32* %2
%19 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %4, i32 %18, i8* %6)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%21 = call i32 @fclose(i32* %7)
br label %22
22: ; preds = %11, %9
%23 = phi i32 [ -1, %9 ], [ 0, %11 ]
ret i32 %23
}