#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 fgetc(int /*<<< orphan*/ *);
scalar_t__ isspace(int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int eatspc(FILE *i) {
  int c;
  int r = 0;
  while ((c = fgetc(i)) != EOF && isspace(c))
    r += c == '\n';
  if (c != EOF)
    ungetc(c, i);
  return r;
}


x86 assembly (clang, -O0):
<eatspc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e8e(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     1177 <eatspc+0x47>
mov    -0xc(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1187 <eatspc+0x57>
jmp    119e <eatspc+0x6e>
cmpl   $0xa,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <eatspc+0x13>
mov    -0xc(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
je     11bc <eatspc+0x8c>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eatspc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    0x2ea2(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%eax
je     1196 <eatspc+0x66>
mov    %eax,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1187 <eatspc+0x57>
xor    %eax,%eax
cmp    $0xa,%ebx
sete   %al
add    %eax,%ebp
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r15),%eax
jne    1160 <eatspc+0x30>
jmp    1196 <eatspc+0x66>
cmp    (%r15),%ebx
je     1196 <eatspc+0x66>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <ungetc@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @eatspc(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %4
br label %5
5: ; preds = %16, %1
%6 = load i32*, i32** %2
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = load i32, i32* %3
%12 = call i64 @isspace(i32 %11)
%13 = icmp ne i64 %12, 0
br label %14
14: ; preds = %10, %5
%15 = phi i1 [ false, %5 ], [ %13, %10 ]
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 10
%19 = zext i1 %18 to i32
%20 = load i32, i32* %4
%21 = add nsw i32 %20, %19
store i32 %21, i32* %4
br label %5
22: ; preds = %14
%23 = load i32, i32* %3
%24 = load i32, i32* @EOF
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %3
%28 = load i32*, i32** %2
%29 = call i32 @ungetc(i32 %27, i32* %28)
br label %30
30: ; preds = %26, %22
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @eatspc(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %22, label %5
5: ; preds = %1, %10
%6 = phi i32 [ %14, %10 ], [ %2, %1 ]
%7 = phi i32 [ %13, %10 ], [ 0, %1 ]
%8 = tail call i64 @isspace(i32 %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = icmp eq i32 %6, 10
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %7, %12
%14 = tail call i32 @fgetc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %22, label %5
17: ; preds = %5
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %6, %18
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @ungetc(i32 %6, i32* %0)
br label %22
22: ; preds = %10, %1, %20, %17
%23 = phi i32 [ %7, %20 ], [ %7, %17 ], [ 0, %1 ], [ %13, %10 ]
ret i32 %23
}