#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 *, int, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ stdin;
size_t strcspn(char *, char *);
int strlen(char *);
int get_line(char *buffer, int bsize) {
  int ch, len;
  fgets(buffer, bsize, stdin);
  buffer[strcspn(buffer, "\n")] = '\0';
  len = strlen(buffer);
  if (len == bsize - 1)
    while ((ch = getchar()) != '\n' && ch != EOF)
      ;
  return len;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11ef <get_line+0xaf>
jmp    11a9 <get_line+0x69>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x21(%rbp)
je     11d5 <get_line+0x95>
mov    -0x10(%rbp),%eax
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11e5 <get_line+0xa5>
jmp    11ea <get_line+0xaa>
jmp    11a9 <get_line+0x69>
jmp    11ef <get_line+0xaf>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcspn@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebp
cmp    %ebp,%eax
jne    11a1 <get_line+0x61>
mov    0x2e5f(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
je     11a1 <get_line+0x61>
cmp    0x0(%rbp),%eax
jne    1190 <get_line+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@EOF = global i32 0
define i32 @get_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %7, i32 %8, i32 %9)
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i64 @strcspn(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 0, i8* %14
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %33
21: ; preds = %2
br label %22
22: ; preds = %31, %21
%23 = call i32 (...) @getchar()
store i32 %23, i32* %5
%24 = icmp ne i32 %23, 10
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br label %29
29: ; preds = %25, %22
%30 = phi i1 [ false, %22 ], [ %28, %25 ]
br i1 %30, label %31, label %32
31: ; preds = %29
br label %22
32: ; preds = %29
br label %33
33: ; preds = %32, %2
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"\0A\00"
@EOF = global i32 0
define i32 @get_line(i8* %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32 %3)
%5 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 0, i8* %6
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %1, -1
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %2, %10
%11 = tail call i32 (...) @getchar()
%12 = icmp ne i32 %11, 10
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %11, %13
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %10, label %16
16: ; preds = %10, %2
ret i32 %7
}