#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 */

/* Variables and functions */
int EOF;
int /*<<< orphan*/ EnvGetHaltExecution(void *);
int EnvGetcRouter(void *, char const *);
char *ExpandStringWithChar(void *, char, char *, size_t *, size_t *, size_t);
char *FillBuffer(void *theEnv, const char *logicalName, size_t *currentPosition,
                 size_t *maximumSize) {
  int c;
  char *buf = NULL;
  c = EnvGetcRouter(theEnv, logicalName);
  if (c == EOF) {
    return (NULL);
  }
  while ((c != '\n') && (c != '\r') && (c != EOF) &&
         (!EnvGetHaltExecution(theEnv))) {
    buf = ExpandStringWithChar(theEnv, c, buf, currentPosition, maximumSize,
                               *maximumSize + 80);
    c = EnvGetcRouter(theEnv, logicalName);
  }
  buf = ExpandStringWithChar(theEnv, '\0', buf, currentPosition, maximumSize,
                             *maximumSize + 80);
  return (buf);
}


x86 assembly (clang, -O0):
<FillBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <EnvGetcRouter@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    117f <FillBuffer+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    124a <FillBuffer+0x11a>
jmp    1184 <FillBuffer+0x54>
xor    %eax,%eax
cmpl   $0xa,-0x2c(%rbp)
mov    %al,-0x39(%rbp)
je     11cd <FillBuffer+0x9d>
xor    %eax,%eax
cmpl   $0xd,-0x2c(%rbp)
mov    %al,-0x39(%rbp)
je     11cd <FillBuffer+0x9d>
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
mov    0x2e3a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x39(%rbp)
je     11cd <FillBuffer+0x9d>
mov    -0x10(%rbp),%rdi
call   1040 <EnvGetHaltExecution@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11dd <FillBuffer+0xad>
jmp    121c <FillBuffer+0xec>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x28(%rbp),%rsi
mov    (%rsi),%r9
add    $0x50,%r9
movsbl %al,%esi
call   1050 <ExpandStringWithChar@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <EnvGetcRouter@plt>
mov    %eax,-0x2c(%rbp)
jmp    1184 <FillBuffer+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x28(%rbp),%rax
mov    (%rax),%r9
add    $0x50,%r9
xor    %esi,%esi
call   1050 <ExpandStringWithChar@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FillBuffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1030 <EnvGetcRouter@plt>
mov    %eax,%ebp
mov    0x2e93(%rip),%rax
cmp    (%rax),%ebp
jne    116a <FillBuffer+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r13d,%r13d
cmp    $0xa,%ebp
je     11cd <FillBuffer+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0xd,%ebp
je     11cd <FillBuffer+0x9d>
mov    0x2e5c(%rip),%rax
cmp    (%rax),%ebp
je     11cd <FillBuffer+0x9d>
mov    %rbx,%rdi
call   1040 <EnvGetHaltExecution@plt>
test   %eax,%eax
jne    11cd <FillBuffer+0x9d>
mov    (%r15),%r9
add    $0x50,%r9
movsbl %bpl,%esi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <ExpandStringWithChar@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <EnvGetcRouter@plt>
mov    %eax,%ebp
cmp    $0xa,%ebp
jne    1180 <FillBuffer+0x50>
mov    (%r15),%r9
add    $0x50,%r9
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %r15,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ExpandStringWithChar@plt>

LLVM IR (-O0):
@EOF = global i32 0
define i8* @FillBuffer(i8* %0, i8* %1, i64* %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i8* null, i8** %11
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i32 @EnvGetcRouter(i8* %12, i8* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %4
store i8* null, i8** %5
br label %61
19: ; preds = %4
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %10
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load i32, i32* %10
%25 = icmp ne i32 %24, 13
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %10
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i8*, i8** %6
%32 = call i32 @EnvGetHaltExecution(i8* %31)
%33 = icmp ne i32 %32, 0
%34 = xor i1 %33, true
br label %35
35: ; preds = %30, %26, %23, %20
%36 = phi i1 [ false, %26 ], [ false, %23 ], [ false, %20 ], [ %34, %30 ]
br i1 %36, label %37, label %51
37: ; preds = %35
%38 = load i8*, i8** %6
%39 = load i32, i32* %10
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %11
%42 = load i64*, i64** %8
%43 = load i64*, i64** %9
%44 = load i64*, i64** %9
%45 = load i64, i64* %44
%46 = add i64 %45, 80
%47 = call i8* @ExpandStringWithChar(i8* %38, i8 signext %40, i8* %41, i64* %42, i64* %43, i64 %46)
store i8* %47, i8** %11
%48 = load i8*, i8** %6
%49 = load i8*, i8** %7
%50 = call i32 @EnvGetcRouter(i8* %48, i8* %49)
store i32 %50, i32* %10
br label %20
51: ; preds = %35
%52 = load i8*, i8** %6
%53 = load i8*, i8** %11
%54 = load i64*, i64** %8
%55 = load i64*, i64** %9
%56 = load i64*, i64** %9
%57 = load i64, i64* %56
%58 = add i64 %57, 80
%59 = call i8* @ExpandStringWithChar(i8* %52, i8 signext 0, i8* %53, i64* %54, i64* %55, i64 %58)
store i8* %59, i8** %11
%60 = load i8*, i8** %11
store i8* %60, i8** %5
br label %61
61: ; preds = %51, %18
%62 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @FillBuffer(i8* %0, i8* %1, i64* %2, i64* %3) {
%5 = tail call i32 @EnvGetcRouter(i8* %0, i8* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %4, %17
%9 = phi i32 [ %22, %17 ], [ %5, %4 ]
%10 = phi i8* [ %21, %17 ], [ null, %4 ]
switch i32 %9, label %11 [
i32 13, label %23
i32 10, label %23
]
11: ; preds = %8
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %9, %12
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = tail call i32 @EnvGetHaltExecution(i8* %0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = trunc i32 %9 to i8
%19 = load i64, i64* %3
%20 = add i64 %19, 80
%21 = tail call i8* @ExpandStringWithChar(i8* %0, i8 signext %18, i8* %10, i64* %2, i64* %3, i64 %20)
%22 = tail call i32 @EnvGetcRouter(i8* %0, i8* %1)
br label %8
23: ; preds = %8, %8, %11, %14
%24 = load i64, i64* %3
%25 = add i64 %24, 80
%26 = tail call i8* @ExpandStringWithChar(i8* %0, i8 signext 0, i8* %10, i64* %2, i64* %3, i64 %25)
br label %27
27: ; preds = %4, %23
%28 = phi i8* [ %26, %23 ], [ null, %4 ]
ret i8* %28
}