#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 fscanf(void *, char *, char *);
int lineNum(void *fp) {
  int i = 0;
  char c = '%';
  while (1 == fscanf(fp, "%c", &c)) {
    if (c == '\n') {
      i++;
    }
  }
  if (i == 0)
    return 1;
  else
    return i;
}


x86 assembly (clang, -O0):
<lineNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x25,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xece(%rip),%rsi
lea    -0x15(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1165 <lineNum+0x55>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
jne    1160 <lineNum+0x50>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <lineNum+0x17>
cmpl   $0x0,-0x14(%rbp)
jne    117b <lineNum+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    1181 <lineNum+0x71>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lineNum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x25,0x7(%rsp)
lea    0xeda(%rip),%rsi
lea    0x7(%rsp),%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    1173 <lineNum+0x63>
xor    %ebp,%ebp
lea    0xec2(%rip),%r14
lea    0x7(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmpb   $0xa,0x7(%rsp)
sete   %al
add    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     1150 <lineNum+0x40>
test   %ebp,%ebp
jne    1178 <lineNum+0x68>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define i32 @lineNum(i8* nocapture %0) {
%2 = alloca i8
store i8 37, i8* %2
%3 = call i32 @fscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %15
5: ; preds = %1, %5
%6 = phi i32 [ %10, %5 ], [ 0, %1 ]
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 10
%9 = zext i1 %8 to i32
%10 = add nuw nsw i32 %6, %9
%11 = call i32 @fscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %5, label %13
13: ; preds = %5
%14 = icmp eq i32 %10, 0
br i1 %14, label %15, label %16
15: ; preds = %1, %13
br label %16
16: ; preds = %13, %15
%17 = phi i32 [ 1, %15 ], [ %10, %13 ]
ret i32 %17
}