#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 /*<<< orphan*/ printf(char *, int);
int main() {
  int nc = 0, nl = 0, nw = 0;
  int i;
  char c;
  while ((c = getchar()) != EOF) {
    nc++;
    if (c == '\n')
      nl++;
  }
  printf("Number of characters in file = %d\n", nc);
  printf("Number of lines in file = %d\n", nl);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
mov    0x2e90(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1187 <main+0x67>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
jne    1182 <main+0x62>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eb4(%rip),%r14
mov    $0x0,%ebp
cmp    (%r14),%al
je     1168 <main+0x48>
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%al
jne    1150 <main+0x30>
lea    0xe91(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [35 x i8] c"Number of characters in file = %d\0A\00"
@.str.1 = [30 x i8] c"Number of lines in file = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %22, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %6
%9 = sext i8 %8 to i32
%10 = load i8, i8* @EOF
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %9, %11
br i1 %12, label %13, label %23
13: ; preds = %7
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %22
22: ; preds = %19, %13
br label %7
23: ; preds = %7
%24 = load i32, i32* %2
%25 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %26)
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [35 x i8] c"Number of characters in file = %d\0A\00"
@.str.1 = [30 x i8] c"Number of lines in file = %d\0A\00"
define i32 @main() {
%1 = tail call signext i8 (...) @getchar()
%2 = load i8, i8* @EOF
%3 = icmp eq i8 %1, %2
br i1 %3, label %15, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %12, %4 ], [ %1, %0 ]
%6 = phi i32 [ %8, %4 ], [ 0, %0 ]
%7 = phi i32 [ %11, %4 ], [ 0, %0 ]
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i8 %5, 10
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = tail call signext i8 (...) @getchar()
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %4
15: ; preds = %4, %0
%16 = phi i32 [ 0, %0 ], [ %11, %4 ]
%17 = phi i32 [ 0, %0 ], [ %8, %4 ]
%18 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i32 0
}