#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int n_lines(FILE *ifp, char comchar) {
  int nlines = 0;
  char line[1000];
  if (ifp == NULL) {
    fprintf(stderr, "ERROR: n_lines.  Null input file.\n");
    return 0;
  }
  while (fgets(line, 1000, ifp) != NULL) {
    if (line[0] != comchar) {
      nlines++;
    }
  }
  if (nlines == 0)
    fprintf(stderr, "** Warning.  n_lines:  No valid lines in input file\n");
  else
    printf("n_lines: %d lines in input file\n", nlines);
  return nlines;
}


x86 assembly (clang, -O0):
<n_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1178 <n_lines+0x48>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <n_lines+0xc6>
jmp    117d <n_lines+0x4d>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11bd <n_lines+0x8d>
movsbl -0x400(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     11b8 <n_lines+0x88>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117d <n_lines+0x4d>
cmpl   $0x0,-0x18(%rbp)
jne    11e1 <n_lines+0xb1>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f0 <n_lines+0xc0>
mov    -0x18(%rbp),%esi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<n_lines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
test   %rdi,%rdi
je     11a4 <n_lines+0x74>
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b6 <n_lines+0x86>
xor    %ebp,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
cmp    %r14b,(%rsp)
setne  %al
add    %eax,%ebp
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1170 <n_lines+0x40>
test   %ebp,%ebp
je     11b6 <n_lines+0x86>
lea    0xebd(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
jmp    11cd <n_lines+0x9d>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
jmp    11c6 <n_lines+0x96>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: n_lines. Null input file.\0A\00"
@.str.1 = [53 x i8] c"** Warning. n_lines: No valid lines in input file\0A\00"
@.str.2 = [33 x i8] c"n_lines: %d lines in input file\0A\00"
define i32 @n_lines(i32* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i32
%7 = alloca [1000 x i8]
store i32* %0, i32** %4
store i8 %1, i8* %5
store i32 0, i32* %6
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %41
13: ; preds = %2
br label %14
14: ; preds = %29, %13
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %4
%17 = call i32* @fgets(i8* %15, i32 1000, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %29
29: ; preds = %26, %19
br label %14
30: ; preds = %14
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %39
36: ; preds = %30
%37 = load i32, i32* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %33
%40 = load i32, i32* %6
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %10
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: n_lines. Null input file.\0A\00"
@.str.1 = [53 x i8] c"** Warning. n_lines: No valid lines in input file\0A\00"
@.str.2 = [33 x i8] c"n_lines: %d lines in input file\0A\00"
define i32 @n_lines(i32* %0, i8 signext %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32* %0, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %27
12: ; preds = %6, %12
%13 = phi i32 [ %17, %12 ], [ 0, %6 ]
%14 = load i8, i8* %4
%15 = icmp ne i8 %14, %1
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %13, %16
%18 = call i32* @fgets(i8* %4, i32 1000, i32* %0)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %12
20: ; preds = %12
%21 = icmp eq i32 %17, 0
br i1 %21, label %22, label %25
22: ; preds = %6, %20
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %27
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %27
27: ; preds = %22, %25, %9
%28 = phi i32 [ 0, %9 ], [ %17, %25 ], [ 0, %22 ]
ret i32 %28
}