#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
char *strerror(int /*<<< orphan*/);
int main(void) {
  FILE *fp;
  char buf[31];
  char *filename = "data.txt";
  if ((fp = fopen(filename, "a+")) == NULL) {
    fprintf(stderr, "Err. fopen(); %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("Enter strings to add to \'%s\' (press ? to terminate)\n", filename);
  while ((fscanf(stdin, "%30s", buf) == 1) && (buf[0] != '?'))
    fprintf(fp, "%s ", buf);
  if (fseek(fp, 0L, SEEK_SET) == -1) {
    fprintf(stderr, "Err. fseek(); %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  while (fscanf(fp, "%s", buf) != -1)
    fprintf(stdout, "%s ", buf);
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11f5 <main+0x75>
mov    0x2e19(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
lea    0xe2a(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x38(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1050 <fscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x41(%rbp)
jne    123c <main+0xbc>
movsbl -0x30(%rbp),%eax
cmp    $0x3f,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    124c <main+0xcc>
jmp    1265 <main+0xe5>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1205 <main+0x85>
mov    -0x10(%rbp),%rdi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
jne    12c1 <main+0x141>
mov    0x2d4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rdx
lea    0xdae(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12c6 <main+0x146>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xd99(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
je     1302 <main+0x182>
mov    0x2cce(%rip),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rdx
lea    0xd60(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12c6 <main+0x146>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe6c(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12c1 <main+0x141>
mov    %rax,%r15
lea    0xe6b(%rip),%rdi
lea    0xe46(%rip),%rsi
call   1040 <printf@plt>
mov    0x2e22(%rip),%r13
mov    0x0(%r13),%rdi
lea    0xe82(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1228 <main+0xa8>
cmpb   $0x3f,(%rsp)
je     1228 <main+0xa8>
lea    0xe6d(%rip),%r14
mov    %rsp,%rbx
lea    0xe5e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1228 <main+0xa8>
cmpb   $0x3f,(%rsp)
jne    1200 <main+0x80>
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0xffffffff,%eax
je     12e2 <main+0x162>
lea    0xe23(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rdi
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
je     12a2 <main+0x122>
mov    0x2d56(%rip),%r13
lea    0xdef(%rip),%r14
mov    %rsp,%rbx
lea    0xdfb(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0x100>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d10(%rip),%rax
mov    (%rax),%rbx
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd2c(%rip),%rsi
jmp    1301 <main+0x181>
mov    0x2cef(%rip),%rax
mov    (%rax),%rbx
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd5b(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@stderr = global i32* null
@.str.2 = [18 x i8] c"Err. fopen(); %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [53 x i8] c"Enter strings to add to '%s' (press ? to terminate)\0A\00"
@stdin = global i32* null
@.str.4 = [5 x i8] c"%30s\00"
@.str.5 = [4 x i8] c"%s \00"
@SEEK_SET = global i32 0
@.str.6 = [18 x i8] c"Err. fseek(); %s\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [31 x i8]
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %4
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32*, i32** @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %30, %15
%19 = load i32*, i32** @stdin
%20 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%21 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 63
br label %28
28: ; preds = %23, %18
%29 = phi i1 [ false, %18 ], [ %27, %23 ]
br i1 %29, label %30, label %34
30: ; preds = %28
%31 = load i32*, i32** %2
%32 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%33 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %32)
br label %18
34: ; preds = %28
%35 = load i32*, i32** %2
%36 = load i32, i32* @SEEK_SET
%37 = call i32 @fseek(i32* %35, i64 0, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %46
39: ; preds = %34
%40 = load i32*, i32** @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %34
br label %47
47: ; preds = %52, %46
%48 = load i32*, i32** %2
%49 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%50 = call i32 @fscanf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %49)
%51 = icmp ne i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32*, i32** @stdout
%54 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%55 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %47
56: ; preds = %47
%57 = load i32*, i32** %2
%58 = call i32 @fclose(i32* %57)
%59 = load i32, i32* @EXIT_SUCCESS
ret i32 %59
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [3 x i8] c"a+\00"
@stderr = global i32* null
@.str.2 = [18 x i8] c"Err. fopen(); %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [53 x i8] c"Enter strings to add to '%s' (press ? to terminate)\0A\00"
@stdin = global i32* null
@.str.4 = [5 x i8] c"%30s\00"
@.str.5 = [4 x i8] c"%s \00"
@SEEK_SET = global i32 0
@.str.6 = [18 x i8] c"Err. fseek(); %s\0A\00"
@.str.7 = [3 x i8] c"%s\00"
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [31 x i8]
%2 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32*, i32** @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = load i32*, i32** @stdin
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%16 = icmp eq i32 %15, 1
%17 = load i8, i8* %2
%18 = icmp ne i8 %17, 63
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %28
20: ; preds = %12, %20
%21 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%22 = load i32*, i32** @stdin
%23 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%24 = icmp eq i32 %23, 1
%25 = load i8, i8* %2
%26 = icmp ne i8 %25, 63
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %20, label %28
28: ; preds = %20, %12
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i32* %3, i64 0, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%34 = icmp eq i32 %33, -1
br i1 %34, label %47, label %42
35: ; preds = %28
%36 = load i32*, i32** @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %32, %42
%43 = load i32*, i32** @stdout
%44 = call i32 @fprintf(i32* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%45 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %2)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %42
47: ; preds = %42, %32
%48 = call i32 @fclose(i32* %3)
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}