#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*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *p1;
  FILE *p2;
  char c = 'x';
  char arr[5];
  p1 = fopen("test.txt", "r");
  if (NULL == p1) {
    printf("打开错误\n");
  }
  p2 = fopen("test1.txt", "w+");
  if (NULL == p2) {
    printf("打开错误\n");
  }
  while (c != '<') {
    fread(&c, 1, 1, p1);
    fwrite(&c, 1, 1, p2);
  }
  printf("%c\n", c);
  fclose(p1);
  fclose(p2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x78,-0x19(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1194 <main+0x44>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c5 <main+0x75>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ca <main+0x7a>
movsbl -0x19(%rbp),%eax
cmp    $0x3c,%eax
je     1204 <main+0xb4>
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
jmp    11ca <main+0x7a>
movsbl -0x19(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movb   $0x78,0x7(%rsp)
lea    0xe8d(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1193 <main+0x33>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe71(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ba <main+0x5a>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0x7(%rsp),%r15
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movsbl 0x7(%rsp),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
cmp    $0x3c,%ebp
jne    11c0 <main+0x60>
lea    0xe28(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"\E6\89\93\E5\BC\80\E9\94\99\E8\AF\AF\0A\00"
@.str.3 = [10 x i8] c"test1.txt\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca [5 x i8]
store i32 0, i32* %1
store i8 120, i8* %4
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp eq i32* null, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
br label %18
18: ; preds = %22, %17
%19 = load i8, i8* %4
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 60
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32*, i32** %2
%24 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fwrite(i8* %4, i32 1, i32 1, i32* %25)
br label %18
27: ; preds = %18
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"test1.txt\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [4 x i8] c"%c\0A\00"
@str.6 = [13 x i8] c"\E6\89\93\E5\BC\80\E9\94\99\E8\AF\AF\00"
define i32 @main() {
%1 = alloca i8
store i8 120, i8* %1
%2 = 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))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %11
11: ; preds = %6, %9
br label %12
12: ; preds = %11, %12
%13 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
%16 = tail call i32 @fputc(i32 %15, i32* %7)
%17 = icmp eq i8 %14, 60
br i1 %17, label %18, label %12
18: ; preds = %12
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 60)
%20 = tail call i32 @fclose(i32* %2)
%21 = tail call i32 @fclose(i32* %7)
ret i32 0
}