#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 */
char EOF;
char getchar();
int get(char *s) {
  int i;
  s[0] = getchar();
  if (s[0] == EOF)
    return 0;
  for (i = 1; s[i - 1] != '\n'; i++)
    s[i] = getchar();
  s[--i] = 0;
  return 1;
}


x86 assembly (clang, -O0):
<get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    0x2eaf(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1150 <get+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11ae <get+0x9e>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1193 <get+0x83>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <get+0x47>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %al,(%rbx)
mov    0x2ec0(%rip),%rcx
cmp    (%rcx),%al
je     115c <get+0x4c>
xor    %ebp,%ebp
cmp    $0xa,%al
je     1153 <get+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %al,0x1(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    $0xa,%al
jne    1140 <get+0x30>
movb   $0x0,(%rbx,%rbp,1)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @get(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call signext i8 (...) @getchar()
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
store i8 %5, i8* %7
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %11, %13
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 0, i32* %2
br label %41
16: ; preds = %1
store i32 1, i32* %4
br label %17
17: ; preds = %32, %16
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %35
26: ; preds = %17
%27 = call signext i8 (...) @getchar()
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %26
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %17
35: ; preds = %17
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
store i8 0, i8* %40
store i32 1, i32* %2
br label %41
41: ; preds = %35, %15
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @get(i8* nocapture %0) {
%2 = tail call signext i8 (...) @getchar()
store i8 %2, i8* %0
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %2, %3
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = icmp eq i8 %2, 10
br i1 %6, label %13, label %7
7: ; preds = %5, %7
%8 = phi i64 [ %11, %7 ], [ 1, %5 ]
%9 = tail call signext i8 (...) @getchar()
%10 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %9, i8* %10
%11 = add nuw i64 %8, 1
%12 = icmp eq i8 %9, 10
br i1 %12, label %13, label %7
13: ; preds = %7, %5
%14 = phi i64 [ 0, %5 ], [ %8, %7 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %1, %13
%17 = phi i32 [ 1, %13 ], [ 0, %1 ]
ret i32 %17
}