#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*/ F_OK;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ isIllegalChar(char *, int);
int do_readText(char *lpFileName, char *lpBuf, size_t dwBufSize) {
  int ret = 0;
  if (0 == access(lpFileName, F_OK)) {
    FILE *fp = fopen(lpFileName, "rb");
    if (fp) {
      fseek(fp, 0L, SEEK_END);
      int fileSize = ftell(fp);
      fseek(fp, 0L, SEEK_SET);
      if (fileSize > 0) {
        if (fileSize > dwBufSize - 1) {
          ret = 5;
        } else {
          ;
          if (fileSize != fread(lpBuf, sizeof(char), fileSize, fp)) {
            ;
            ret = 2;
          } else {
            ;
            if (isIllegalChar(lpBuf, fileSize)) {
              ;
              ret = 4;
            };
          }
        }
      }
      fclose(fp);
    } else {
      ret = 3;
    }
  } else {
    ;
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<do_readText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a7 <do_readText+0x137>
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     129b <do_readText+0x12b>
mov    -0x28(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <fseek@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    128d <do_readText+0x11d>
movslq -0x2c(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jbe    122d <do_readText+0xbd>
movl   $0x5,-0x1c(%rbp)
jmp    1288 <do_readText+0x118>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
je     1261 <do_readText+0xf1>
movl   $0x2,-0x1c(%rbp)
jmp    1283 <do_readText+0x113>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <isIllegalChar@plt>
cmp    $0x0,%rax
je     127e <do_readText+0x10e>
movl   $0x4,-0x1c(%rbp)
jmp    1283 <do_readText+0x113>
jmp    1288 <do_readText+0x118>
jmp    128d <do_readText+0x11d>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12a2 <do_readText+0x132>
movl   $0x3,-0x1c(%rbp)
jmp    12ae <do_readText+0x13e>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_readText>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbp
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    123d <do_readText+0xcd>
lea    0xe5c(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1238 <do_readText+0xc8>
mov    %rax,%r12
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %r12,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
test   %ebp,%ebp
jle    122e <do_readText+0xbe>
mov    %ebp,%eax
add    $0xffffffffffffffff,%r15
mov    $0x5,%ebx
cmp    %rax,%r15
jb     122e <do_readText+0xbe>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   1030 <fread@plt>
mov    $0x2,%ebx
cmp    %eax,%ebp
jne    122e <do_readText+0xbe>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <isIllegalChar@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
shl    $0x2,%ebx
mov    %r12,%rdi
call   1040 <fclose@plt>
jmp    123d <do_readText+0xcd>
mov    $0x3,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @do_readText(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%10 = load i8*, i8** %4
%11 = load i32, i32* @F_OK
%12 = call i64 @access(i8* %10, i32 %11)
%13 = icmp eq i64 0, %12
br i1 %13, label %14, label %59
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = load i32*, i32** %8
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %57
19: ; preds = %14
%20 = load i32*, i32** %8
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i64 0, i32 %21)
%23 = load i32*, i32** %8
%24 = call i32 @ftell(i32* %23)
store i32 %24, i32* %9
%25 = load i32*, i32** %8
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i64 0, i32 %26)
%28 = load i32, i32* %9
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %54
30: ; preds = %19
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = load i64, i64* %6
%34 = sub i64 %33, 1
%35 = icmp ugt i64 %32, %34
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 5, i32* %7
br label %53
37: ; preds = %30
%38 = load i32, i32* %9
%39 = load i8*, i8** %5
%40 = load i32, i32* %9
%41 = load i32*, i32** %8
%42 = call i32 @fread(i8* %39, i32 1, i32 %40, i32* %41)
%43 = icmp ne i32 %38, %42
br i1 %43, label %44, label %45
44: ; preds = %37
store i32 2, i32* %7
br label %52
45: ; preds = %37
%46 = load i8*, i8** %5
%47 = load i32, i32* %9
%48 = call i64 @isIllegalChar(i8* %46, i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %45
store i32 4, i32* %7
br label %51
51: ; preds = %50, %45
br label %52
52: ; preds = %51, %44
br label %53
53: ; preds = %52, %36
br label %54
54: ; preds = %53, %19
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
br label %58
57: ; preds = %14
store i32 3, i32* %7
br label %58
58: ; preds = %57, %54
br label %60
59: ; preds = %3
store i32 1, i32* %7
br label %60
60: ; preds = %59, %58
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @do_readText(i8* nocapture %0, i8* %1, i64 %2) {
%4 = load i32, i32* @F_OK
%5 = tail call i64 @access(i8* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %31
7: ; preds = %3
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %31, label %10
10: ; preds = %7
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %8, i64 0, i32 %11)
%13 = tail call i32 @ftell(i32* %8)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %8, i64 0, i32 %14)
%16 = icmp sgt i32 %13, 0
br i1 %16, label %17, label %28
17: ; preds = %10
%18 = zext i32 %13 to i64
%19 = add i64 %2, -1
%20 = icmp ult i64 %19, %18
br i1 %20, label %28, label %21
21: ; preds = %17
%22 = tail call i32 @fread(i8* %1, i32 1, i32 %13, i32* %8)
%23 = icmp eq i32 %13, %22
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = tail call i64 @isIllegalChar(i8* %1, i32 %13)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i32 0, i32 4
br label %28
28: ; preds = %24, %21, %17, %10
%29 = phi i32 [ 0, %10 ], [ 5, %17 ], [ 2, %21 ], [ %27, %24 ]
%30 = tail call i32 @fclose(i32* %8)
br label %31
31: ; preds = %3, %28, %7
%32 = phi i32 [ %29, %28 ], [ 3, %7 ], [ 1, %3 ]
ret i32 %32
}