#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;
  p1 = fopen("test.txt", "r");
  if (NULL == p1) {
    printf("打开错误\n");
  }
  p2 = fopen("test1.txt", "w+");
  if (NULL == p2) {
    printf("打开错误\n");
  }
  char c = 'x';
  for (fread(&c, 1, 1, p1); 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)
lea    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1190 <main+0x40>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11c1 <main+0x71>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x78,-0x19(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x19(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0x19(%rbp),%eax
cmp    $0x3c,%eax
je     1218 <main+0xc8>
jmp    11eb <main+0x9b>
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    11d9 <main+0x89>
movsbl -0x19(%rbp),%esi
lea    0xe03(%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
lea    0xe92(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    118e <main+0x2e>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b5 <main+0x55>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
movb   $0x78,0x7(%rsp)
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
cmpb   $0x3c,0x7(%rsp)
je     1209 <main+0xa9>
lea    0x7(%rsp),%r15
nopl   (%rax)
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    11e0 <main+0x80>
lea    0xe08(%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
store i32 0, i32* %1
%5 = 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* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = 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* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
store i8 120, i8* %4
%17 = load i32*, i32** %2
%18 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %17)
br label %19
19: ; preds = %24, %16
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 60
br i1 %22, label %23, label %29
23: ; preds = %19
br label %24
24: ; preds = %23
%25 = load i32*, i32** %2
%26 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fwrite(i8* %4, i32 1, i32 1, i32* %27)
br label %19
29: ; preds = %19
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %3
%36 = call i32 @fclose(i32* %35)
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
%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 = %9, %6
store i8 120, i8* %1
%12 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%13 = load i8, i8* %1
%14 = icmp eq i8 %13, 60
br i1 %14, label %21, label %15
15: ; preds = %11, %15
%16 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = tail call i32 @fputc(i32 %18, i32* %7)
%20 = icmp eq i8 %17, 60
br i1 %20, label %21, label %15
21: ; preds = %15, %11
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 60)
%23 = tail call i32 @fclose(i32* %2)
%24 = tail call i32 @fclose(i32* %7)
ret i32 0
}