#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*/ *fgets(char *, size_t, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ stdin;
int strlen(char *);
int readLine(char *buff, size_t sz) {
  int ch, extra;
  if (fgets(buff, sz, stdin) == NULL)
    return 1;
  char *temp = buff;
  while (*temp == ' ') {
    temp++;
  }
  if (*temp == '\n')
    return 3;
  if (buff[strlen(buff) - 1] != '\n') {
    extra = 0;
    while (((ch = getchar()) != '\n') && (ch != EOF))
      extra = 1;
    return (extra == 1) ? 2 : 0;
  }
  buff[strlen(buff) - 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    116c <readLine+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    126a <readLine+0x13a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1195 <readLine+0x65>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <readLine+0x44>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11b1 <readLine+0x81>
movl   $0x3,-0x4(%rbp)
jmp    126a <readLine+0x13a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1242 <readLine+0x112>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x31(%rbp)
je     120e <readLine+0xde>
mov    -0x1c(%rbp),%eax
mov    0x2dda(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    121e <readLine+0xee>
jmp    122a <readLine+0xfa>
movl   $0x1,-0x20(%rbp)
jmp    11e2 <readLine+0xb2>
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    126a <readLine+0x13a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
test   %rax,%rax
je     116a <readLine+0x3a>
mov    %rbx,%rax
nopl   (%rax)
movzbl (%rax),%ecx
cmp    $0x20,%cl
jne    115e <readLine+0x2e>
add    $0x1,%rax
jmp    1150 <readLine+0x20>
cmp    $0xa,%cl
jne    1171 <readLine+0x41>
mov    $0x3,%ebx
jmp    11d1 <readLine+0xa1>
mov    $0x1,%ebx
jmp    11d1 <readLine+0xa1>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1195 <readLine+0x65>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %ebx,%ebx
jmp    11d1 <readLine+0xa1>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11d1 <readLine+0xa1>
mov    0x2e36(%rip),%r14
cmp    (%r14),%eax
je     11d1 <readLine+0xa1>
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11d1 <readLine+0xa1>
cmp    (%r14),%eax
jne    11c0 <readLine+0x90>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i32 @readLine(i8* %0, i64 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32* @fgets(i8* %0, i64 %1, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %35, label %6
6: ; preds = %2, %9
%7 = phi i8* [ %10, %9 ], [ %0, %2 ]
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 32, label %9
i8 10, label %35
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
br i1 %17, label %30, label %18
18: ; preds = %11
%19 = tail call i32 (...) @getchar()
%20 = icmp ne i32 %19, 10
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %19, %21
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %24, label %35
24: ; preds = %18, %24
%25 = tail call i32 (...) @getchar()
%26 = icmp ne i32 %25, 10
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %25, %27
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %24, label %35
30: ; preds = %11
%31 = tail call i32 @strlen(i8* %0)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 0, i8* %34
br label %35
35: ; preds = %6, %24, %18, %30, %2
%36 = phi i32 [ 1, %2 ], [ 0, %30 ], [ 0, %18 ], [ 2, %24 ], [ 3, %6 ]
ret i32 %36
}