#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 numcols(char *name) {
  FILE *fff;
  char line[10000];
  char *spt[10000];
  char *sx;
  int nsplit, 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;
    }
    freeup(spt, nsplit);
    fclose(fff);
    return nsplit;
  }
}


x86 assembly (clang, -O0):
<numcols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x15fc0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x15fc0(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <numcols+0x30>
lea    0xe75(%rip),%rdi
call   1030 <fatalx@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    0xe75(%rip),%rdx
call   1080 <openit@plt>
lea    -0x2730(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x2710,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     124f <numcols+0xef>
lea    -0x2730(%rbp),%rdi
lea    -0x15fb0(%rbp),%rsi
mov    $0x32,%edx
call   1040 <splitup@plt>
mov    %eax,-0x15fbc(%rbp)
cmpl   $0x0,-0x15fbc(%rbp)
jne    11f3 <numcols+0x93>
jmp    11a4 <numcols+0x44>
mov    -0x15fb0(%rbp),%rax
mov    %rax,-0x15fb8(%rbp)
mov    -0x15fb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    122b <numcols+0xcb>
lea    -0x15fb0(%rbp),%rdi
mov    -0x15fbc(%rbp),%esi
call   1070 <freeup@plt>
jmp    11a4 <numcols+0x44>
lea    -0x15fb0(%rbp),%rdi
mov    -0x15fbc(%rbp),%esi
call   1070 <freeup@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x15fbc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x15fc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numcols>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x15fa8,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1181 <numcols+0x21>
lea    0xe84(%rip),%rdi
call   1030 <fatalx@plt>
lea    0xe8c(%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>
test   %rax,%rax
je     1213 <numcols+0xb3>
lea    0x10(%rsp),%r15
lea    0x2720(%rsp),%r14
jmp    11d7 <numcols+0x77>
nopl   (%rax)
mov    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    $0x2710,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1213 <numcols+0xb3>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x32,%edx
call   1040 <splitup@plt>
test   %eax,%eax
je     11c0 <numcols+0x60>
mov    %eax,%ebp
mov    0x2720(%rsp),%rax
movzbl (%rax),%ebx
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <freeup@plt>
cmp    $0x23,%bl
je     11c0 <numcols+0x60>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
jmp    1213 <numcols+0xb3>
mov    %ebp,%eax
add    $0x15fa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 @numcols(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10000 x i8]
%6 = alloca [10000 x i8*]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %9
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @fatalx(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i8*, i8** %3
%16 = call i32 @openit(i8* %15, i32** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %37, %28, %14
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32* @fgets(i8* %18, i32 10000, i32* %19)
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %48
22: ; preds = %17
%23 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %6, i64 0, i64 0
%25 = call i32 @splitup(i8* %23, i8** %24, i32 50)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %17
29: ; preds = %22
%30 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %6, i64 0, i64 0
%31 = load i8*, i8** %30
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 35
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %6, i64 0, i64 0
%39 = load i32, i32* %8
%40 = call i32 @freeup(i8** %38, i32 %39)
br label %17
41: ; preds = %29
%42 = getelementptr inbounds [10000 x i8*], [10000 x i8*]* %6, i64 0, i64 0
%43 = load i32, i32* %8
%44 = call i32 @freeup(i8** %42, i32 %43)
%45 = load i32*, i32** %4
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %8
store i32 %47, i32* %2
br label %48
48: ; preds = %41, %17
%49 = load i32, i32* %2
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 @numcols(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 %33, 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, %26
%19 = call i32 @splitup(i8* %6, i8** %17, i32 50)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i8*, i8** %17
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 35
%25 = call i32 @freeup(i8** %17, i32 %19)
br i1 %24, label %26, label %30
26: ; preds = %21, %18
%27 = load i32*, i32** %2
%28 = call i32* @fgets(i8* %6, i32 10000, i32* %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %33, label %18
30: ; preds = %21
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %26, %11, %30
%34 = phi i32 [ %19, %30 ], [ undef, %11 ], [ undef, %26 ]
ret i32 %34
}