#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 getchar();
char *cc_getline(char *buf, unsigned int max_len) {
  int c;
  char *ret = buf;
  unsigned int char_cnt = 0;
  c = getchar();
  while (c != EOF && c != '\n' && char_cnt < max_len) {
    *buf = c;
    ++buf;
    ++char_cnt;
    c = getchar();
  }
  *buf = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<cc_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
mov    0x2ea4(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     116a <cc_getline+0x5a>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     116a <cc_getline+0x5a>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    117a <cc_getline+0x6a>
jmp    11a9 <cc_getline+0x99>
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
jmp    1138 <cc_getline+0x28>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_getline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %r14,%rbx
cmp    $0xa,%eax
je     1171 <cc_getline+0x61>
mov    0x2eb4(%rip),%r15
mov    %r14,%rbx
cmp    (%r15),%eax
je     1171 <cc_getline+0x61>
mov    %r14,%rbx
test   %r12d,%r12d
je     1171 <cc_getline+0x61>
mov    $0x1,%ebp
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %al,(%rbx)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1171 <cc_getline+0x61>
cmp    (%r15),%eax
je     1171 <cc_getline+0x61>
lea    0x1(%rbp),%ecx
cmp    %r12d,%ebp
mov    %ecx,%ebp
jb     1150 <cc_getline+0x40>
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i8* @cc_getline(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %6
store i32 0, i32* %7
%9 = call i32 (...) @getchar()
store i32 %9, i32* %5
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp ult i32 %18, %19
br label %21
21: ; preds = %17, %14, %10
%22 = phi i1 [ false, %14 ], [ false, %10 ], [ %20, %17 ]
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = load i32, i32* %5
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %3
store i8 %25, i8* %26
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %3
%29 = load i32, i32* %7
%30 = add i32 %29, 1
store i32 %30, i32* %7
%31 = call i32 (...) @getchar()
store i32 %31, i32* %5
br label %10
32: ; preds = %21
%33 = load i8*, i8** %3
store i8 0, i8* %33
%34 = load i8*, i8** %6
ret i8* %34
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @cc_getline(i8* returned writeonly %0, i32 %1) {
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp ne i32 %3, 10
%7 = and i1 %6, %5
%8 = icmp ne i32 %1, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %24
10: ; preds = %2, %10
%11 = phi i32 [ %16, %10 ], [ 0, %2 ]
%12 = phi i8* [ %15, %10 ], [ %0, %2 ]
%13 = phi i32 [ %17, %10 ], [ %3, %2 ]
%14 = trunc i32 %13 to i8
store i8 %14, i8* %12
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = add nuw i32 %11, 1
%17 = tail call i32 (...) @getchar()
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
%20 = icmp ne i32 %17, 10
%21 = and i1 %20, %19
%22 = icmp ult i32 %16, %1
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %10, label %24
24: ; preds = %10, %2
%25 = phi i8* [ %0, %2 ], [ %15, %10 ]
store i8 0, i8* %25
ret i8* %0
}