#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned long);
void do_wc_l(FILE *f) {
  unsigned long n;
  int c;
  int prev = '\n';
  n = 0;
  while ((c = getc(f)) != EOF) {
    if (c == '\n') {
      n++;
    }
    prev = c;
  }
  if (prev != '\n') {
    n++;
  }
  printf("%lu\n", n);
}


x86 assembly (clang, -O0):
<do_wc_l>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xa,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%eax
je     1177 <do_wc_l+0x57>
cmpl   $0xa,-0x14(%rbp)
jne    116c <do_wc_l+0x4c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    113b <do_wc_l+0x1b>
cmpl   $0xa,-0x18(%rbp)
je     118d <do_wc_l+0x6d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_wc_l>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <getc@plt>
mov    0x2eb2(%rip),%r15
cmp    (%r15),%eax
jne    1144 <do_wc_l+0x24>
mov    $0xa,%ebp
xor    %ebx,%ebx
jmp    116a <do_wc_l+0x4a>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%ebp
xor    %eax,%eax
cmp    $0xa,%ebp
sete   %al
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <getc@plt>
cmp    (%r15),%eax
jne    1150 <do_wc_l+0x30>
xor    %esi,%esi
cmp    $0xa,%ebp
setne  %sil
add    %rbx,%rsi
lea    0xe83(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [5 x i8] c"%lu\0A\00"
define void @do_wc_l(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 10, i32* %5
store i64 0, i64* %3
br label %6
6: ; preds = %17, %1
%7 = load i32*, i32** %2
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %3
%16 = add i64 %15, 1
store i64 %16, i64* %3
br label %17
17: ; preds = %14, %11
%18 = load i32, i32* %4
store i32 %18, i32* %5
br label %6
19: ; preds = %6
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i64, i64* %3
%24 = add i64 %23, 1
store i64 %24, i64* %3
br label %25
25: ; preds = %22, %19
%26 = load i64, i64* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %26)
ret void
}

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