#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 fread(char *, int, int, int /*<<< orphan*/ *);
char ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *p;
  p = fopen("test.txt", "r");
  if (NULL == p) {
    printf("打开错误\n");
  }
  printf("%ld\n", ftell(p));
  int i = 0;
  char c = 'x';
  while (c != '<') {
    if (fread(&c, 1, 1, p) != 1)
      ;
    { printf("读取文件异常\n"); }
    printf("%c\n", c);
  }
  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    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1070 <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>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
movsbl %al,%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
movb   $0x78,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x3c,%eax
je     1209 <main+0xb9>
mov    -0x10(%rbp),%rcx
lea    -0x15(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11e4 <main+0x94>
jmp    11e4 <main+0x94>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x15(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b5 <main+0x65>
movsbl -0x15(%rbp),%esi
lea    0xe1e(%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   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8d(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1193 <main+0x33>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
movsbl %al,%esi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movb   $0x78,0xf(%rsp)
lea    0xf(%rsp),%r14
lea    0xe57(%rip),%r15
lea    0xe4c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
movsbl 0xf(%rsp),%ebp
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x3c,%ebp
jne    11d0 <main+0x70>
lea    0xe06(%rip),%rdi
mov    $0x3c,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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 = [5 x i8] c"%ld\0A\00"
@.str.4 = [20 x i8] c"\E8\AF\BB\E5\8F\96\E6\96\87\E4\BB\B6\E5\BC\82\E5\B8\B8\0A\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 = load i32*, i32** %2
%12 = call signext i8 @ftell(i32* %11)
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 0, i32* %3
store i8 120, i8* %4
br label %15
15: ; preds = %24, %10
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 60
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = load i32*, i32** %2
%21 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %20)
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %19
br label %24
24: ; preds = %23, %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %15
29: ; preds = %15
%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)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@.str.5 = [4 x i8] c"%c\0A\00"
@str = [19 x i8] c"\E8\AF\BB\E5\8F\96\E6\96\87\E4\BB\B6\E5\BC\82\E5\B8\B8\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 signext i8 @ftell(i32* %2)
%8 = sext i8 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %8)
store i8 120, i8* %1
br label %10
10: ; preds = %6, %10
%11 = call i32 @fread(i8* %1, i32 1, i32 1, i32* %2)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = load i8, i8* %1
%14 = sext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = icmp eq i8 %13, 60
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 60)
%19 = tail call i32 @fclose(i32* %2)
ret i32 0
}