#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 *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char **);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  fp = fopen("data.txt", "r");
  fclose(fp);
  if (!(fp = fopen("data.txt", "r"))) {
    printf("Cant open file.\n");
    return 1;
  }
  char word1[80], word2[80];
  fscanf(fp, "%s", &word1);
  fscanf(fp, "%s", &word2);
  printf("%s", word1);
  printf(" %s\n", word2);
  fclose(fp);
  if (fp = fopen("newdata.txt", "w")) {
    fprintf(fp, "Hello World");
    fclose(fp);
  } else {
    printf("Opening file 'newdata.txt' failed.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeae(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe8e(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c4 <main+0x74>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1273 <main+0x123>
mov    -0x18(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0xc0(%rbp),%rdx
lea    0xe29(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdf5(%rip),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     125e <main+0x10e>
mov    -0x18(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    126c <main+0x11c>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xe98(%rip),%rbx
lea    0xe84(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1235 <main+0xd5>
mov    %rax,%rbx
lea    0xe55(%rip),%r14
lea    0x50(%rsp),%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <fscanf@plt>
mov    %rsp,%r12
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <fscanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe20(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe0c(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1248 <main+0xe8>
mov    %rax,%rbx
lea    0xdff(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1254 <main+0xf4>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1256 <main+0xf6>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Cant open file.\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c" %s\0A\00"
@.str.5 = [12 x i8] c"newdata.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [12 x i8] c"Hello World\00"
@.str.8 = [36 x i8] c"Opening file 'newdata.txt' failed.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [80 x i8]
%8 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = 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* %9, i32** %6
%10 = load i32*, i32** %6
%11 = call i32 @fclose(i32* %10)
%12 = 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* %12, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %39
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = bitcast [80 x i8]* %7 to i8**
%19 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %18)
%20 = load i32*, i32** %6
%21 = bitcast [80 x i8]* %8 to i8**
%22 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %21)
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %29, i32** %6
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %16
%32 = load i32*, i32** %6
%33 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %38
36: ; preds = %16
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
store i32 0, i32* %3
br label %39
39: ; preds = %38, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c" %s\0A\00"
@.str.5 = [12 x i8] c"newdata.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [12 x i8] c"Hello World\00"
@str = [16 x i8] c"Cant open file.\00"
@str.9 = [35 x i8] c"Opening file 'newdata.txt' failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = 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))
%6 = tail call i32 @fclose(i32* %5)
%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 = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%14 = bitcast [80 x i8]* %3 to i8**
%15 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %14)
%16 = bitcast [80 x i8]* %4 to i8**
%17 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%20 = call i32 @fclose(i32* %7)
%21 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %11
%24 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i64 11, i64 1, i32* %21)
%25 = call i32 @fclose(i32* %21)
br label %28
26: ; preds = %11
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.9, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
br label %29
29: ; preds = %28, %9
%30 = phi i32 [ 0, %28 ], [ 1, %9 ]
ret i32 %30
}