#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 getc(int /*<<< orphan*/);
int /*<<< orphan*/ print_stat(long, long, char *);
int /*<<< orphan*/ stdin;
void readstdin(void) {
  long bytes = 0;
  long lines = 0;
  int c;
  while ((c = getc(stdin)) != EOF) {
    bytes++;
    if (c == '\n')
      lines++;
  }
  print_stat(bytes, lines, "");
}


x86 assembly (clang, -O0):
<readstdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%eax
je     117f <readstdin+0x5f>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0xa,-0x14(%rbp)
jne    117a <readstdin+0x5a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1138 <readstdin+0x18>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdx
call   1030 <print_stat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstdin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb9(%rip),%r15
mov    (%r15),%edi
call   1040 <getc@plt>
mov    0x2ea2(%rip),%r12
cmp    (%r12),%eax
jne    114b <readstdin+0x2b>
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    116d <readstdin+0x4d>
xor    %r14d,%r14d
xor    %ebx,%ebx
add    $0x1,%r14
xor    %ecx,%ecx
cmp    $0xa,%eax
sete   %cl
add    %rcx,%rbx
mov    (%r15),%edi
call   1040 <getc@plt>
cmp    (%r12),%eax
jne    1150 <readstdin+0x30>
lea    0xe8c(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <print_stat@plt>

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
@.str = [1 x i8] zeroinitializer
define void @readstdin() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
store i64 0, i64* %1
store i64 0, i64* %2
br label %4
4: ; preds = %17, %0
%5 = load i32, i32* @stdin
%6 = call i32 @getc(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %4
%10 = load i64, i64* %1
%11 = add nsw i64 %10, 1
store i64 %11, i64* %1
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i64, i64* %2
%16 = add nsw i64 %15, 1
store i64 %16, i64* %2
br label %17
17: ; preds = %14, %9
br label %4
18: ; preds = %4
%19 = load i64, i64* %1
%20 = load i64, i64* %2
%21 = call i32 @print_stat(i64 %19, i64 %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
@.str = [1 x i8] zeroinitializer
define void @readstdin() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @getc(i32 %1)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %17, label %5
5: ; preds = %0, %5
%6 = phi i32 [ %14, %5 ], [ %2, %0 ]
%7 = phi i64 [ %9, %5 ], [ 0, %0 ]
%8 = phi i64 [ %12, %5 ], [ 0, %0 ]
%9 = add nuw nsw i64 %7, 1
%10 = icmp eq i32 %6, 10
%11 = zext i1 %10 to i64
%12 = add nuw nsw i64 %8, %11
%13 = load i32, i32* @stdin
%14 = tail call i32 @getc(i32 %13)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %5
17: ; preds = %5, %0
%18 = phi i64 [ 0, %0 ], [ %12, %5 ]
%19 = phi i64 [ 0, %0 ], [ %9, %5 ]
%20 = tail call i32 @print_stat(i64 %19, i64 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret void
}