#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 getLine(char *buff, size_t sz) {
  int ch, extra;
  if (fgets(buff, sz, stdin) == NULL)
    return 1;
  if (buff[0] == ' ' || buff[0] == '\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):
<getLine>:
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 <getLine+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1251 <getLine+0x121>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     118c <getLine+0x5c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1198 <getLine+0x68>
movl   $0x3,-0x4(%rbp)
jmp    1251 <getLine+0x121>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1229 <getLine+0xf9>
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,-0x29(%rbp)
je     11f5 <getLine+0xc5>
mov    -0x1c(%rbp),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1205 <getLine+0xd5>
jmp    1211 <getLine+0xe1>
movl   $0x1,-0x20(%rbp)
jmp    11c9 <getLine+0x99>
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <getLine+0x121>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%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):
<getLine>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
test   %rax,%rax
je     1180 <getLine+0x50>
mov    (%r14),%al
mov    $0x3,%ebx
cmp    $0xa,%al
je     1185 <getLine+0x55>
cmp    $0x20,%al
je     1185 <getLine+0x55>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    118f <getLine+0x5f>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
xor    %ebx,%ebx
jmp    1185 <getLine+0x55>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     1185 <getLine+0x55>
mov    0x2e3c(%rip),%r14
cmp    (%r14),%eax
je     1185 <getLine+0x55>
mov    $0x2,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     1185 <getLine+0x55>
cmp    (%r14),%eax
jne    11b0 <getLine+0x80>
jmp    1185 <getLine+0x55>

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

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