#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 /*<<< orphan*/ fatalx(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ freeup(char **, int);
int /*<<< orphan*/ openit(char *, int /*<<< orphan*/ **, char *);
int splitup(char *, char **, int);
int numlines(char *name) {
  FILE *fff;
  char line[10000];
  char *spt[10000];
  char *sx;
  int nsplit, num = 0;
  num = 0;
  if (name == NULL)
    fatalx("(numlines)  no name");
  openit(name, &fff, "r");
  while (fgets(line, 10000, fff) != NULL) {
    nsplit = splitup(line, spt, 50);
    if (nsplit == 0)
      continue;
    sx = spt[0];
    if (sx[0] == '#') {
      freeup(spt, nsplit);
      continue;
    }
    ++num;
    freeup(spt, nsplit);
  }
  fclose(fff);
  return num;
}


x86 assembly (clang, -O0):
<numlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x15fb0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x15fb0(%rbp)
movl   $0x0,-0x15fb0(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119a <numlines+0x3a>
lea    0xe6b(%rip),%rdi
call   1030 <fatalx@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   1080 <openit@plt>
lea    -0x2720(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2710,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     125b <numlines+0xfb>
lea    -0x2720(%rbp),%rdi
lea    -0x15fa0(%rbp),%rsi
mov    $0x32,%edx
call   1040 <splitup@plt>
mov    %eax,-0x15fac(%rbp)
cmpl   $0x0,-0x15fac(%rbp)
jne    11fd <numlines+0x9d>
jmp    11ae <numlines+0x4e>
mov    -0x15fa0(%rbp),%rax
mov    %rax,-0x15fa8(%rbp)
mov    -0x15fa8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1235 <numlines+0xd5>
lea    -0x15fa0(%rbp),%rdi
mov    -0x15fac(%rbp),%esi
call   1070 <freeup@plt>
jmp    11ae <numlines+0x4e>
mov    -0x15fb0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x15fb0(%rbp)
lea    -0x15fa0(%rbp),%rdi
mov    -0x15fac(%rbp),%esi
call   1070 <freeup@plt>
jmp    11ae <numlines+0x4e>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x15fb0(%rbp),%eax
add    $0x15fb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numlines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x15fa0,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
jne    117f <numlines+0x1f>
lea    0xe86(%rip),%rdi
call   1030 <fatalx@plt>
lea    0xe8e(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <openit@plt>
mov    0x8(%rsp),%rdx
lea    0x10(%rsp),%rdi
mov    $0x2710,%esi
call   1060 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1208 <numlines+0xa8>
lea    0x10(%rsp),%rbx
lea    0x2720(%rsp),%rbp
jmp    11e1 <numlines+0x81>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %eax,%esi
call   1070 <freeup@plt>
mov    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1208 <numlines+0xa8>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1040 <splitup@plt>
test   %eax,%eax
je     11ca <numlines+0x6a>
mov    0x2720(%rsp),%rcx
cmpb   $0x23,(%rcx)
je     11c0 <numlines+0x60>
add    $0x1,%r14d
jmp    11c0 <numlines+0x60>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    %r14d,%eax
add    $0x15fa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"(numlines) no name\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @numlines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [10000 x i8]
%5 = alloca [10000 x i8*]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %8
store i32 0, i32* %8
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @fatalx(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i8*, i8** %2
%15 = call i32 @openit(i8* %14, i32** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %40, %36, %27, %13
%17 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%18 = load i32*, i32** %3
%19 = call i32* @fgets(i8* %17, i32 10000, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %46
21: ; preds = %16
%22 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %5, i64 0, i64 0
%24 = call i32 @splitup(i8* %22, i8** %23, i32 50)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %16
28: ; preds = %21
%29 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %5, i64 0, i64 0
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 35
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %5, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @freeup(i8** %37, i32 %38)
br label %16
40: ; preds = %28
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
%43 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %5, i64 0, i64 0
%44 = load i32, i32* %7
%45 = call i32 @freeup(i8** %43, i32 %44)
br label %16
46: ; preds = %16
%47 = load i32*, i32** %3
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* %8
ret i32 %49
}

LLVM IR (-O2):
@.str = [20 x i8] c"(numlines) no name\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @numlines(i8* %0) {
%2 = alloca i32*
%3 = alloca [10000 x i8]
%4 = alloca [10000 x i8*]
%5 = bitcast i32** %2 to i8*
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%7 = bitcast [10000 x i8*]* %4 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @fatalx(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = call i32 @openit(i8* %0, i32** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32*, i32** %2
%14 = call i32* @fgets(i8* %6, i32 10000, i32* %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %39, label %16
16: ; preds = %11
%17 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %4, i64 0, i64 0
br label %18
18: ; preds = %16, %33
%19 = phi i32 [ 0, %16 ], [ %34, %33 ]
br label %20
20: ; preds = %18, %29
%21 = call i32 @splitup(i8* %6, i8** %17, i32 50)
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i8*, i8** %17
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 35
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = call i32 @freeup(i8** %17, i32 %21)
br label %29
29: ; preds = %27, %20
%30 = load i32*, i32** %2
%31 = call i32* @fgets(i8* %6, i32 10000, i32* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %39, label %20
33: ; preds = %23
%34 = add nuw nsw i32 %19, 1
%35 = call i32 @freeup(i8** %17, i32 %21)
%36 = load i32*, i32** %2
%37 = call i32* @fgets(i8* %6, i32 10000, i32* %36)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %18
39: ; preds = %33, %29, %11
%40 = phi i32 [ 0, %11 ], [ %19, %29 ], [ %34, %33 ]
%41 = load i32*, i32** %2
%42 = call i32 @fclose(i32* %41)
ret i32 %40
}