#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  FILE *fp;
  char words[41];
  if ((fp = fopen("wordy", "a+")) == NULL) {
    fprintf(stderr, "Can't open the file \"wordy\".\n");
    exit(EXIT_FAILURE);
  }
  puts("Enter words to add to the file; press the #");
  puts("key at the beginning of a line to terminate.");
  while ((fscanf(stdin, "%40s", words) == 1) && (words[0] != '#'))
    fprintf(fp, "%s\n", words);
  puts("File contents:");
  rewind(fp);
  while (fscanf(fp, "%s", words) == 1)
    puts(words);
  puts("Done!");
  if (fclose(fp) != 0)
    fprintf(stderr, "Error closing file\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cc <main+0x5c>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe87(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x51(%rbp)
jne    121b <main+0xab>
movsbl -0x50(%rbp),%eax
cmp    $0x23,%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    122b <main+0xbb>
jmp    1248 <main+0xd8>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
lea    -0x50(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    11e4 <main+0x74>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1288 <main+0x118>
lea    -0x50(%rbp),%rdi
call   1030 <puts@plt>
jmp    125d <main+0xed>
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12be <main+0x14e>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xe7c(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12ab <main+0x13b>
mov    %rax,%r15
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e2d(%rip),%r13
mov    0x0(%r13),%rdi
lea    0xeba(%rip),%rsi
mov    %rsp,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    121a <main+0xaa>
cmpb   $0x23,(%rsp)
je     121a <main+0xaa>
lea    0xea5(%rip),%r14
mov    %rsp,%rbx
lea    0xe96(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    121a <main+0xaa>
cmpb   $0x23,(%rsp)
jne    11f0 <main+0x80>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1050 <rewind@plt>
lea    0xe63(%rip),%rsi
mov    %rsp,%rdx
mov    %r15,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    126b <main+0xfb>
mov    %rsp,%rbx
lea    0xe49(%rip),%r14
nop
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     1250 <main+0xe0>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     129b <main+0x12b>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"wordy\00"
@.str.1 = [3 x i8] c"a+\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Can't open the file \22wordy\22.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [44 x i8] c"Enter words to add to the file; press the #\00"
@.str.4 = [45 x i8] c"key at the beginning of a line to terminate.\00"
@stdin = global i32* null
@.str.5 = [5 x i8] c"%40s\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [15 x i8] c"File contents:\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [6 x i8] c"Done!\00"
@.str.10 = [20 x i8] c"Error closing file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [41 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i32 @puts(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %30, %15
%19 = load i32*, i32** @stdin
%20 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%21 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, 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 [41 x i8], [41 x i8]* %7, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 35
br label %28
28: ; preds = %23, %18
%29 = phi i1 [ false, %18 ], [ %27, %23 ]
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load i32*, i32** %6
%32 = ptrtoint i32* %31 to i32
%33 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %33)
br label %18
35: ; preds = %28
%36 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%37 = load i32*, i32** %6
%38 = call i32 @rewind(i32* %37)
br label %39
39: ; preds = %44, %35
%40 = load i32*, i32** %6
%41 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%42 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = getelementptr inbounds [41 x i8], [41 x i8]* %7, i64 0, i64 0
%46 = call i32 @puts(i8* %45)
br label %39
47: ; preds = %39
%48 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%49 = load i32*, i32** %6
%50 = call i64 @fclose(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %55
55: ; preds = %52, %47
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"wordy\00"
@.str.1 = [3 x i8] c"a+\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Can't open the file \22wordy\22.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [44 x i8] c"Enter words to add to the file; press the #\00"
@.str.4 = [45 x i8] c"key at the beginning of a line to terminate.\00"
@stdin = global i32* null
@.str.5 = [5 x i8] c"%40s\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [15 x i8] c"File contents:\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [6 x i8] c"Done!\00"
@.str.10 = [20 x i8] c"Error closing file\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [41 x i8]
%4 = getelementptr inbounds [41 x i8], [41 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%15 = load i32*, i32** @stdin
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%17 = icmp eq i32 %16, 1
%18 = load i8, i8* %4
%19 = icmp ne i8 %18, 35
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %21, label %32
21: ; preds = %12
%22 = ptrtoint i32* %5 to i64
%23 = trunc i64 %22 to i32
br label %24
24: ; preds = %21, %24
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%26 = load i32*, i32** @stdin
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%28 = icmp eq i32 %27, 1
%29 = load i8, i8* %4
%30 = icmp ne i8 %29, 35
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %24, label %32
32: ; preds = %24, %12
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @rewind(i32* %5)
%35 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %41
37: ; preds = %32, %37
%38 = call i32 @puts(i8* %4)
%39 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%40 = icmp eq i32 %39, 1
br i1 %40, label %37, label %41
41: ; preds = %37, %32
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%43 = call i64 @fclose(i32* %5)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %48
48: ; preds = %45, %41
ret i32 0
}