#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 */
scalar_t__ handleUserInput(char *);
scalar_t__ read(int, char *, unsigned int);
int readUserInput(int fd) {
  char readChar;
  static char buffer[100];
  static int bufferPos = 0;
  while (read(fd, &readChar, 1u) > 0) {
    if (readChar != '\n') {
      buffer[bufferPos] = readChar;
      bufferPos += 1;
      if (bufferPos == 100) {
        bufferPos = 0;
      }
    } else {
      buffer[bufferPos] = '\0';
      if (handleUserInput(buffer) != 0) {
        return -1;
      }
      bufferPos = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readUserInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jle    11d5 <readUserInput+0xb5>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1192 <readUserInput+0x72>
mov    -0x9(%rbp),%dl
movslq 0x2f47(%rip),%rcx
lea    0x2edc(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    0x2f37(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f2e(%rip)
cmpl   $0x64,0x2f27(%rip)
jne    118d <readUserInput+0x6d>
movl   $0x0,0x2f17(%rip)
jmp    11d0 <readUserInput+0xb0>
movslq 0x2f0b(%rip),%rcx
lea    0x2ea0(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e95(%rip),%rdi
call   1040 <handleUserInput@plt>
cmp    $0x0,%rax
je     11c6 <readUserInput+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <readUserInput+0xbc>
movl   $0x0,0x2ed4(%rip)
jmp    112b <readUserInput+0xb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readUserInput>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jle    11a3 <readUserInput+0x83>
lea    0x2efc(%rip),%r14
lea    0x7(%rsp),%r15
xor    %ebp,%ebp
jmp    1177 <readUserInput+0x57>
nopl   (%rax)
mov    %cl,(%rax,%r14,1)
lea    0x1(%rax),%ecx
cmp    $0x64,%ecx
cmove  %ebp,%ecx
mov    %ecx,0x2f41(%rip)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jle    11a3 <readUserInput+0x83>
movzbl 0x7(%rsp),%ecx
movslq 0x2f21(%rip),%rax
cmp    $0xa,%cl
jne    1150 <readUserInput+0x30>
movb   $0x0,(%rax,%r14,1)
mov    %r14,%rdi
call   1040 <handleUserInput@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     115d <readUserInput+0x3d>
mov    $0xffffffff,%eax
jmp    11a5 <readUserInput+0x85>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@readUserInput.buffer = internal global [100 x i8] zeroinitializer
@readUserInput.bufferPos = internal global i32 0
define i32 @readUserInput(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
br label %5
5: ; preds = %32, %1
%6 = load i32, i32* %3
%7 = call i64 @read(i32 %6, i8* %4, i32 1)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %5
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i8, i8* %4
%15 = load i32, i32* @readUserInput.bufferPos
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* @readUserInput.buffer, i64 0, i64 %16
store i8 %14, i8* %17
%18 = load i32, i32* @readUserInput.bufferPos
%19 = add nsw i32 %18, 1
store i32 %19, i32* @readUserInput.bufferPos
%20 = load i32, i32* @readUserInput.bufferPos
%21 = icmp eq i32 %20, 100
br i1 %21, label %22, label %23
22: ; preds = %13
store i32 0, i32* @readUserInput.bufferPos
br label %23
23: ; preds = %22, %13
br label %32
24: ; preds = %9
%25 = load i32, i32* @readUserInput.bufferPos
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* @readUserInput.buffer, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i64 @handleUserInput(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @readUserInput.buffer, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -1, i32* %2
br label %34
31: ; preds = %24
store i32 0, i32* @readUserInput.bufferPos
br label %32
32: ; preds = %31, %23
br label %5
33: ; preds = %5
store i32 0, i32* %2
br label %34
34: ; preds = %33, %30
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@readUserInput.buffer = internal global [100 x i8] zeroinitializer
@readUserInput.bufferPos = internal unnamed_addr global i32 0
define i32 @readUserInput(i32 %0) {
%2 = alloca i8
%3 = call i64 @read(i32 %0, i8* %2, i32 1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1, %18
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 10
%8 = load i32, i32* @readUserInput.bufferPos
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [100 x i8], [100 x i8]* @readUserInput.buffer, i64 0, i64 %9
br i1 %7, label %15, label %11
11: ; preds = %5
store i8 %6, i8* %10
%12 = add nsw i32 %8, 1
%13 = icmp eq i32 %12, 100
%14 = select i1 %13, i32 0, i32 %12
br label %18
15: ; preds = %5
store i8 0, i8* %10
%16 = tail call i64 @handleUserInput(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @readUserInput.buffer, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15, %11
%19 = phi i32 [ %14, %11 ], [ 0, %15 ]
store i32 %19, i32* @readUserInput.bufferPos
%20 = call i64 @read(i32 %0, i8* %2, i32 1)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %5, label %22
22: ; preds = %15, %18, %1
%23 = phi i32 [ 0, %1 ], [ 0, %18 ], [ -1, %15 ]
ret i32 %23
}