#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*/ Error_write(int, char *, int, char *, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int FileUtil_readToChar(FILE *Fp, char *string, int strLen, char endChar) {
  int count = 0;
  char ch;
  ch = fgetc(Fp);
  while (!feof(Fp) && count < strLen - 1 && ch != endChar) {
    string[count++] = ch;
    ch = getc(Fp);
  }
  if (count == strLen - 1) {
    Error_write(22, "FileUtil_readToChar", 2, "strLen = %d", strLen);
    return 0;
  }
  string[count] = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<FileUtil_readToChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x25(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x26(%rbp)
jne    11aa <FileUtil_readToChar+0x6a>
mov    -0x24(%rbp),%ecx
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x26(%rbp)
jge    11aa <FileUtil_readToChar+0x6a>
movsbl -0x25(%rbp),%eax
movsbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
test   $0x1,%al
jne    11ba <FileUtil_readToChar+0x7a>
jmp    11e3 <FileUtil_readToChar+0xa3>
mov    -0x25(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x25(%rbp)
jmp    116b <FileUtil_readToChar+0x2b>
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1221 <FileUtil_readToChar+0xe1>
mov    -0x1c(%rbp),%r8d
mov    $0x16,%edi
lea    0xdfc(%rip),%rsi
mov    $0x2,%edx
lea    0xe04(%rip),%rcx
call   1030 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <FileUtil_readToChar+0xf4>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_readToChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <fgetc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <feof@plt>
lea    -0x1(%r13),%ecx
xor    %r14d,%r14d
cmp    %r12b,%bl
je     11c1 <FileUtil_readToChar+0x81>
test   %eax,%eax
jne    11c1 <FileUtil_readToChar+0x81>
cmp    $0x2,%r13d
jl     11c1 <FileUtil_readToChar+0x81>
mov    %r13,0x10(%rsp)
mov    %ecx,0xc(%rsp)
mov    %ecx,%r13d
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %bl,(%r15,%r14,1)
add    $0x1,%r14
mov    %rbp,%rdi
call   1060 <getc@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1050 <feof@plt>
cmp    %r12b,%bl
je     11b8 <FileUtil_readToChar+0x78>
test   %eax,%eax
jne    11b8 <FileUtil_readToChar+0x78>
cmp    %r13,%r14
jb     1190 <FileUtil_readToChar+0x50>
mov    0x10(%rsp),%r13
mov    0xc(%rsp),%ecx
cmp    %ecx,%r14d
jne    11ea <FileUtil_readToChar+0xaa>
lea    0xe33(%rip),%rsi
lea    0xe40(%rip),%rcx
mov    $0x16,%edi
mov    $0x2,%edx
mov    %r13d,%r8d
call   1030 <Error_write@plt>
xor    %eax,%eax
jmp    11f7 <FileUtil_readToChar+0xb7>
mov    %r14d,%eax
movb   $0x0,(%r15,%rax,1)
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"FileUtil_readToChar\00"
@.str.1 = [12 x i8] c"strLen = %d\00"
define i32 @FileUtil_readToChar(i32* %0, i8* %1, i32 %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca i8
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8 %3, i8* %9
store i32 0, i32* %10
%12 = load i32*, i32** %6
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %11
br label %14
14: ; preds = %31, %4
%15 = load i32*, i32** %6
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %29, label %18
18: ; preds = %14
%19 = load i32, i32* %10
%20 = load i32, i32* %8
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
%26 = load i8, i8* %9
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br label %29
29: ; preds = %23, %18, %14
%30 = phi i1 [ false, %18 ], [ false, %14 ], [ %28, %23 ]
br i1 %30, label %31, label %40
31: ; preds = %29
%32 = load i8, i8* %11
%33 = load i8*, i8** %7
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 %32, i8* %37
%38 = load i32*, i32** %6
%39 = call signext i8 @getc(i32* %38)
store i8 %39, i8* %11
br label %14
40: ; preds = %29
%41 = load i32, i32* %10
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 1
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %8
%47 = call i32 @Error_write(i32 22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %46)
store i32 0, i32* %5
br label %53
48: ; preds = %40
%49 = load i8*, i8** %7
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
store i32 1, i32* %5
br label %53
53: ; preds = %48, %45
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@.str = [20 x i8] c"FileUtil_readToChar\00"
@.str.1 = [12 x i8] c"strLen = %d\00"
define i32 @FileUtil_readToChar(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2, i8 signext %3) {
%5 = tail call signext i8 @fgetc(i32* %0)
%6 = tail call i32 @feof(i32* %0)
%7 = icmp ne i32 %6, 0
%8 = add nsw i32 %2, -1
%9 = icmp slt i32 %2, 2
%10 = or i1 %7, %9
%11 = icmp eq i8 %5, %3
%12 = or i1 %11, %10
br i1 %12, label %29, label %13
13: ; preds = %4
%14 = zext i32 %8 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %18, %15 ]
%17 = phi i8 [ %5, %13 ], [ %20, %15 ]
%18 = add nuw nsw i64 %16, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 %17, i8* %19
%20 = tail call signext i8 @getc(i32* %0)
%21 = tail call i32 @feof(i32* %0)
%22 = icmp ne i32 %21, 0
%23 = icmp uge i64 %18, %14
%24 = select i1 %22, i1 true, i1 %23
%25 = icmp eq i8 %20, %3
%26 = or i1 %25, %24
br i1 %26, label %27, label %15
27: ; preds = %15
%28 = trunc i64 %18 to i32
br label %29
29: ; preds = %27, %4
%30 = phi i32 [ 0, %4 ], [ %28, %27 ]
%31 = icmp eq i32 %30, %8
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @Error_write(i32 22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %37
34: ; preds = %29
%35 = zext i32 %30 to i64
%36 = getelementptr inbounds i8, i8* %1, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %34, %32
%38 = phi i32 [ 0, %32 ], [ 1, %34 ]
ret i32 %38
}