#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
main() {
  FILE *F1, *F2;
  F1 = fopen("zvezdi", "r");
  F2 = fopen("dd", "a+");
  char str[50];
  fscanf(F1, "%s", str);
  while (!feof(F1)) {
    fscanf(F1, "%s", str);
    printf("%s\n", str);
    fprintf(F2, "%s\n", str);
  }
  fclose(F1);
  fclose(F2);
  F1 = fopen("zvezdi", "w");
  F2 = fopen("dd", "r");
  while (!feof(F2)) {
    fscanf(F2, "%s", str);
    fprintf(F1, "%s\n", str);
  }
  fclose(F1);
  fclose(F2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe63(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cf <main+0x6f>
jmp    120c <main+0xac>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe31(%rip),%rsi
call   1050 <fscanf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11b1 <main+0x51>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xddb(%rip),%rdi
lea    0xdea(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xdcd(%rip),%rdi
lea    0xdc4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    126a <main+0x10a>
jmp    1297 <main+0x137>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   1060 <fprintf@plt>
jmp    124c <main+0xec>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
lea    0xe8c(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xe7f(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe6f(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
call   1050 <fscanf@plt>
mov    %r12,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1203 <main+0xa3>
lea    0xe51(%rip),%r15
mov    %rsp,%rbx
lea    0xe4a(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
mov    %r12,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d0 <main+0x70>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xde6(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xdd9(%rip),%rdi
lea    0xdd0(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1288 <main+0x128>
lea    0xdbd(%rip),%r15
mov    %rsp,%r12
lea    0xdb6(%rip),%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1260 <main+0x100>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"zvezdi\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"dd\00"
@.str.3 = [3 x i8] c"a+\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [50 x i8]
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %2
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %15, %0
%11 = load i32*, i32** %2
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = load i32*, i32** %2
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %3
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %22)
br label %10
24: ; preds = %10
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %29, i32** %2
%30 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %3
br label %31
31: ; preds = %36, %24
%32 = load i32*, i32** %3
%33 = call i32 @feof(i32* %32)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32*, i32** %3
%38 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%39 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i32*, i32** %2
%41 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%42 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %31
43: ; preds = %31
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
%46 = load i32*, i32** %3
%47 = call i32 @fclose(i32* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"zvezdi\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"dd\00"
@.str.3 = [3 x i8] c"a+\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@.str.6 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%6 = call i32 @feof(i32* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0, %8
%9 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%11 = call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%12 = call i32 @feof(i32* %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8, %0
%15 = call i32 @fclose(i32* %2)
%16 = call i32 @fclose(i32* %3)
%17 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32* @fopen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @feof(i32* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %14, %21
%22 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%23 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%24 = call i32 @feof(i32* %18)
%25 = icmp eq i32 %24, 0
br i1 %25, label %21, label %26
26: ; preds = %21, %14
%27 = call i32 @fclose(i32* %17)
%28 = call i32 @fclose(i32* %18)
ret i32 0
}