#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*/ check_io(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int col_len(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int get_line(char *buf, int siz, int maxcol) {
  int length;
  fflush(stdout);
  if (fgets(buf, siz + 1, stdin) == NULL) {
    check_io(stdin, "stdin", 0);
  }
  length = strlen(buf);
  if (buf[length - 1] != '\n') {
    int eatchar;
    do {
      eatchar = fgetc(stdin);
    } while (eatchar != EOF && eatchar != '\n');
    check_io(stdin, "stdin", 0);
    return 0;
  }
  if (maxcol > 0 && (length > maxcol || col_len(buf) > maxcol)) {
    return 0;
  }
  return length;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11b9 <get_line+0x59>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
xor    %edx,%edx
call   1070 <check_io@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1244 <get_line+0xe4>
jmp    11e4 <get_line+0x84>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
mov    0x2ddf(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     1216 <get_line+0xb6>
cmpl   $0xa,-0x20(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11e4 <get_line+0x84>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
xor    %edx,%edx
call   1070 <check_io@plt>
movl   $0x0,-0x4(%rbp)
jmp    127e <get_line+0x11e>
cmpl   $0x0,-0x18(%rbp)
jle    1278 <get_line+0x118>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     126c <get_line+0x10c>
mov    -0x10(%rbp),%rdi
call   1060 <col_len@plt>
cmp    -0x18(%rbp),%eax
jle    1278 <get_line+0x118>
movl   $0x0,-0x4(%rbp)
jmp    127e <get_line+0x11e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r12
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
add    $0x1,%ebp
mov    0x2e60(%rip),%rbx
mov    (%rbx),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a9 <get_line+0x49>
mov    (%rbx),%edi
lea    0xe5e(%rip),%rsi
xor    %edx,%edx
call   1070 <check_io@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
cltq
cmpb   $0xa,-0x1(%rax,%r12,1)
jne    11dc <get_line+0x7c>
test   %r14d,%r14d
jle    11d7 <get_line+0x77>
xor    %r15d,%r15d
cmp    %r14d,%ebp
jg     1214 <get_line+0xb4>
mov    %r12,%rdi
call   1060 <col_len@plt>
cmp    %r14d,%eax
jg     1214 <get_line+0xb4>
mov    %ebp,%r15d
jmp    1214 <get_line+0xb4>
mov    0x2dfd(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edi
call   1040 <fgetc@plt>
cmp    $0xa,%eax
je     1201 <get_line+0xa1>
cmp    0x0(%rbp),%eax
jne    11f0 <get_line+0x90>
mov    (%rbx),%edi
lea    0xdf6(%rip),%rsi
xor    %r15d,%r15d
xor    %edx,%edx
call   1070 <check_io@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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