#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*/ printf(char *, ...);
int main(void) {
  FILE *p;
  p = fopen("test.txt", "r");
  if (NULL == p) {
    printf("打开错误\n");
  }
  char c = 'x';
  for (fread(&c, 1, 1, p); c != '<'; fread(&c, 1, 1, p))
    ;
  printf("%c\n", c);
  fclose(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1180 <main+0x40>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movb   $0x78,-0x11(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x3c,%eax
je     11c3 <main+0x83>
jmp    11aa <main+0x6a>
mov    -0x10(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
jmp    1198 <main+0x58>
movsbl -0x11(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117b <main+0x2b>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
movb   $0x78,0x7(%rsp)
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmpb   $0x3c,0x7(%rsp)
je     11cc <main+0x7c>
lea    0x7(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmpb   $0x3c,0x7(%rsp)
jne    11b0 <main+0x60>
lea    0xe38(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 = [4 x i8] c"%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
store i8 120, i8* %3
%10 = load i32*, i32** %2
%11 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %10)
br label %12
12: ; preds = %17, %9
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 60
br i1 %15, label %16, label %20
16: ; preds = %12
br label %17
17: ; preds = %16
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %18)
br label %12
20: ; preds = %12
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@str = [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, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
store i8 120, i8* %1
%7 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 60
br i1 %9, label %14, label %10
10: ; preds = %6, %10
%11 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%12 = load i8, i8* %1
%13 = icmp eq i8 %12, 60
br i1 %13, label %14, label %10
14: ; preds = %10, %6
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 60)
%16 = tail call i32 @fclose(i32* %2)
ret i32 0
}