#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*/ buf_in;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, char *);
size_t strcspn(char *, char *);
int build_input(char questions_file[], char output_file[]) {
  FILE *input_stream;
  FILE *output_stream;
  char buf_in[BUFSIZ];
  char buf_out[BUFSIZ];
  input_stream = fopen(questions_file, "r");
  output_stream = fopen(output_file, "w+");
  while (fgets(buf_in, sizeof(buf_in), input_stream)) {
    buf_in[strcspn(buf_in, "\n")] = 0;
    printf("%s ", buf_in);
    if (scanf("%s", buf_out) == EOF)
      printf("EOF reached!\n");
    fprintf(output_stream, "%s\n", buf_out);
  }
  fclose(input_stream);
  fclose(output_stream);
  return 0;
}


x86 assembly (clang, -O0):
<build_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x50(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1280 <build_input+0x110>
mov    -0x48(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <strcspn@plt>
mov    -0x48(%rbp),%rsi
movb   $0x0,(%rsi,%rax,1)
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xdc5(%rip),%rdi
call   1080 <scanf@plt>
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
jne    1267 <build_input+0xf7>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x40(%rbp),%rdx
mov    -0x20(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11f6 <build_input+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_input>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    0x2e40(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r12
lea    0xe34(%rip),%rsi
mov    %r13,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r13
jmp    11f2 <build_input+0x72>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
lea    0xe22(%rip),%rsi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1252 <build_input+0xd2>
mov    %rbx,%rdi
lea    0xdff(%rip),%rsi
call   1060 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
lea    0xde6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd9(%rip),%rdi
mov    %r15,%rsi
call   1090 <scanf@plt>
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%rax
jne    11e0 <build_input+0x60>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
jmp    11e0 <build_input+0x60>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [14 x i8] c"EOF reached!\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @build_input(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %9
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
br label %21
21: ; preds = %35, %2
%22 = trunc i64 %11 to i32
%23 = load i32*, i32** %5
%24 = call i64 @fgets(i8* %13, i32 %22, i32* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %21
%27 = call i64 @strcspn(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds i8, i8* %13, i64 %27
store i8 0, i8* %28
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%30 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = load i32*, i32** %6
%37 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %16)
br label %21
38: ; preds = %21
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** %7
ret i32 0
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.6 = [4 x i8] c"%s\0A\00"
@str = [13 x i8] c"EOF reached!\00"
define i32 @build_input(i8* nocapture %0, i8* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %2, %20
%12 = call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %5, i64 %12
store i8 0, i8* %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%15 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%16 = load i64, i64* @EOF
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%22 = call i64 @fgets(i8* %5, i32 %3, i32* %7)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %11
24: ; preds = %20, %2
%25 = call i32 @fclose(i32* %7)
%26 = call i32 @fclose(i32* %8)
ret i32 0
}