#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int readLine(char *buffer, int size) {
  int count;
  fgets(buffer, size - 1, stdin);
  for (count = 0; count < size - 1; count++) {
    if (buffer[count] == '\0' || buffer[count] == '\r' || buffer[count] == '\n')
      break;
  }
  buffer[count] = '\0';
  if (count == 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    0x2eb8(%rip),%rax
mov    (%rax),%edx
call   1030 <fgets@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a6 <readLine+0x96>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     118e <readLine+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     118e <readLine+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1193 <readLine+0x83>
jmp    11a6 <readLine+0x96>
jmp    1198 <readLine+0x88>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <readLine+0x2e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x18(%rbp)
jne    11c8 <readLine+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    11cf <readLine+0xbf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    -0x1(%rbp),%r14d
mov    0x2ec4(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%esi
call   1030 <fgets@plt>
xor    %ecx,%ecx
cmp    $0x2,%ebp
jl     116e <readLine+0x5e>
mov    %r14d,%eax
xor    %ecx,%ecx
mov    $0x2401,%edx
jmp    1159 <readLine+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rax
je     116b <readLine+0x5b>
movzbl (%rbx,%rcx,1),%esi
cmp    $0xd,%rsi
ja     1150 <readLine+0x40>
bt     %rsi,%rdx
jae    1150 <readLine+0x40>
jmp    116e <readLine+0x5e>
mov    %r14d,%ecx
mov    %ecx,%eax
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @readLine(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = sub nsw i32 %8, 1
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %7, i32 %9, i32 %10)
store i32 0, i32* %6
br label %12
12: ; preds = %43, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %46
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %41, label %25
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 13
br i1 %32, label %41, label %33
33: ; preds = %25
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 10
br i1 %40, label %41, label %42
41: ; preds = %33, %25, %17
br label %46
42: ; preds = %33
br label %43
43: ; preds = %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %12
46: ; preds = %41, %12
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %46
store i32 0, i32* %3
br label %55
54: ; preds = %46
store i32 1, i32* %3
br label %55
55: ; preds = %54, %53
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @readLine(i8* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = load i32, i32* @stdin
%5 = tail call i32 @fgets(i8* %0, i32 %3, i32 %4)
%6 = icmp sgt i32 %1, 1
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %7, %13
%10 = phi i64 [ 0, %7 ], [ %14, %13 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %13 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
13: ; preds = %9
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %18, label %9
16: ; preds = %9, %9, %9
%17 = trunc i64 %10 to i32
br label %18
18: ; preds = %13, %16, %2
%19 = phi i32 [ 0, %2 ], [ %17, %16 ], [ %3, %13 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
%22 = icmp ne i32 %19, 0
%23 = zext i1 %22 to i32
ret i32 %23
}