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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  FILE *fp;
  char s[100];
  fp = fopen("datafile.txt", "w");
  while (fgets(s, sizeof(s), stdin) != NULL) {
    fputs(s, fp);
    puts(s);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11b5 <main+0x65>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <fputs@plt>
lea    -0x80(%rbp),%rdi
call   1030 <puts@plt>
jmp    1179 <main+0x29>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xea0(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    0x2e72(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11b8 <main+0x68>
mov    %rsp,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
test   %rax,%rax
jne    1190 <main+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"datafile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [100 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
br label %5
5: ; preds = %10, %0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 100, i32 %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32 @fputs(i8* %11, i32* %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = call i32 @puts(i8* %14)
br label %5
16: ; preds = %5
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"datafile.txt\00"
@.str.1 = [2 x i8] c"w\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32* @fgets(i8* %2, i32 100, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %0, %7
%8 = call i32 @fputs(i8* %2, i32* %3)
%9 = call i32 @puts(i8* %2)
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %2, i32 100, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %7
13: ; preds = %7, %0
%14 = call i32 @fclose(i32* %3)
ret i32 0
}