#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int getLine(char *prmpt, char *buff, size_t sz) {
  int ch, extra;
  if (prmpt != NULL) {
    printf("%s", prmpt);
    fflush(stdout);
  }
  if (fgets(buff, sz, stdin) == NULL)
    return 1;
  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    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118d <getLine+0x3d>
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11b9 <getLine+0x69>
movl   $0x1,-0x4(%rbp)
jmp    1272 <getLine+0x122>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%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     124a <getLine+0xfa>
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x31(%rbp)
je     1216 <getLine+0xc6>
mov    -0x24(%rbp),%eax
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1226 <getLine+0xd6>
jmp    1232 <getLine+0xe2>
movl   $0x1,-0x28(%rbp)
jmp    11ea <getLine+0x9a>
mov    -0x28(%rbp),%edx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <getLine+0x122>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%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):
<getLine>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
test   %rdi,%rdi
je     117c <getLine+0x2c>
mov    %rdi,%rsi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fgets@plt>
test   %rax,%rax
je     11b9 <getLine+0x69>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11c0 <getLine+0x70>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %ebx,%ebx
jmp    11f1 <getLine+0xa1>
mov    $0x1,%ebx
jmp    11f1 <getLine+0xa1>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
je     11f1 <getLine+0xa1>
mov    0x2e0b(%rip),%r14
cmp    (%r14),%eax
je     11f1 <getLine+0xa1>
mov    $0x2,%ebx
nop
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
je     11f1 <getLine+0xa1>
cmp    (%r14),%eax
jne    11e0 <getLine+0x90>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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