#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 getchar();
int get_single(void) {
  int count = 0;
  int c = getchar();
  if (c == '\n')
    return c;
  while (getchar() != '\n')
    ++count;
  return count == 0 ? c : 0;
}


x86 assembly (clang, -O0):
<get_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jne    1141 <get_single+0x31>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <get_single+0x7c>
jmp    1146 <get_single+0x36>
mov    $0x0,%al
call   1030 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1167 <get_single+0x57>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1146 <get_single+0x36>
cmpl   $0x0,-0x8(%rbp)
jne    117c <get_single+0x6c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <get_single+0x76>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    1186 <get_single+0x76>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_single>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    $0xa,%eax
cmp    $0xa,%cl
je     1145 <get_single+0x35>
movsbl %cl,%ebx
mov    $0x1,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0xffffffff,%ebp
cmp    $0xa,%al
jne    1130 <get_single+0x20>
xor    %eax,%eax
test   %ebp,%ebp
cmove  %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_single() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call signext i8 (...) @getchar()
%5 = sext i8 %4 to i32
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 10
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* %3
store i32 %9, i32* %1
br label %26
10: ; preds = %0
br label %11
11: ; preds = %15, %10
%12 = call signext i8 (...) @getchar()
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %11
18: ; preds = %11
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32, i32* %3
br label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %21
%25 = phi i32 [ %22, %21 ], [ 0, %23 ]
store i32 %25, i32* %1
br label %26
26: ; preds = %24, %8
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
define i32 @get_single() {
%1 = tail call signext i8 (...) @getchar()
%2 = sext i8 %1 to i32
%3 = icmp eq i8 %1, 10
br i1 %3, label %12, label %4
4: ; preds = %0, %4
%5 = phi i32 [ %8, %4 ], [ 0, %0 ]
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 10
%8 = add nuw nsw i32 %5, 1
br i1 %7, label %9, label %4
9: ; preds = %4
%10 = icmp eq i32 %5, 0
%11 = select i1 %10, i32 %2, i32 0
br label %12
12: ; preds = %0, %9
%13 = phi i32 [ %11, %9 ], [ 10, %0 ]
ret i32 %13
}