#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void *ioThreadFunction7() {
  char buff1[1025];
  int times = 500000000;
  FILE *fileIn;
  FILE *fileOut;
  fileIn = fopen("./test_file7", "r");
  fileOut = fopen("./test_file7_out", "w+");
  while (times > 0) {
    while (fgets(buff1, 1024, fileIn) != NULL) {
      fputs(buff1, fileOut);
    }
    fclose(fileIn);
    fclose(fileOut);
    fileIn = fopen("./test_file7", "r");
    fileOut = fopen("./test_file7_out", "w+");
    times--;
  }
}


x86 assembly (clang, -O0):
<ioThreadFunction7>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x1dcd6500,-0x414(%rbp)
65 cd 1d
lea    0xea4(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x420(%rbp)
lea    0xe99(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    1235 <ioThreadFunction7+0xf5>
jmp    119b <ioThreadFunction7+0x5b>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11d5 <ioThreadFunction7+0x95>
lea    -0x410(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1040 <fputs@plt>
jmp    119b <ioThreadFunction7+0x5b>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe0c(%rip),%rdi
lea    0xe12(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x420(%rbp)
lea    0xe01(%rip),%rdi
lea    0xe0b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x428(%rbp)
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
jmp    1189 <ioThreadFunction7+0x49>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ioThreadFunction7>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xea8(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xea1(%rip),%r12
lea    0xeab(%rip),%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    $0x1dcd6500,%r15d
mov    %rsp,%rbx
jmp    119b <ioThreadFunction7+0x5b>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <ioThreadFunction7+0x50>
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xe39(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    -0x1(%r15),%eax
cmp    $0x1,%r15d
mov    %eax,%r15d
ja     119b <ioThreadFunction7+0x5b>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"./test_file7\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"./test_file7_out\00"
@.str.3 = [3 x i8] c"w+\00"
define i8* @ioThreadFunction7() {
%1 = alloca i8*
%2 = alloca [1025 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 500000000, i32* %3
%6 = 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* %6, i32** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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* %7, i32** %5
br label %8
8: ; preds = %21, %0
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %8
br label %12
12: ; preds = %17, %11
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32 @fputs(i8* %18, i32* %19)
br label %12
21: ; preds = %12
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = 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* %26, i32** %4
%27 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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* %27, i32** %5
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %8
30: ; preds = %8
%31 = load i8*, i8** %1
ret i8* %31
}

LLVM IR (-O2):
@.str = [13 x i8] c"./test_file7\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"./test_file7_out\00"
@.str.3 = [3 x i8] c"w+\00"
define noalias i8* @ioThreadFunction7() {
%1 = alloca [1025 x i8]
%2 = getelementptr inbounds [1025 x i8], [1025 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 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %5
5: ; preds = %0, %15
%6 = phi i32* [ %4, %0 ], [ %19, %15 ]
%7 = phi i32* [ %3, %0 ], [ %18, %15 ]
%8 = phi i32 [ 500000000, %0 ], [ %20, %15 ]
%9 = call i32* @fgets(i8* %2, i32 1024, i32* %7)
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %5, %11
%12 = call i32 @fputs(i8* %2, i32* %6)
%13 = call i32* @fgets(i8* %2, i32 1024, i32* %7)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %11
15: ; preds = %11, %5
%16 = call i32 @fclose(i32* %7)
%17 = call i32 @fclose(i32* %6)
%18 = 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))
%19 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%20 = add nsw i32 %8, -1
%21 = icmp ugt i32 %8, 1
br i1 %21, label %5, label %22
22: ; preds = %15
ret i8* undef
}