#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*/ *);
scalar_t__ is_blank(char *);
int /*<<< orphan*/ trim_line(char *);
int read_line(FILE *ifp, char *line, int limit) {
  static FILE *current_fp = NULL;
  static int current_line = 0;
  if (ifp != current_fp) {
    current_fp = ifp;
    current_line = 0;
  }
  do {
    if (fgets(line, limit, ifp) == NULL)
      return 0;
    ++current_line;
  } while (is_blank(line));
  trim_line(line);
  return current_line;
}


x86 assembly (clang, -O0):
<read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2ef2(%rip),%rax
je     1169 <read_line+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee1(%rip)
movl   $0x0,0x2edf(%rip)
jmp    116e <read_line+0x3e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    1194 <read_line+0x64>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <read_line+0x98>
mov    0x2eae(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ea5(%rip)
mov    -0x18(%rbp),%rdi
call   1050 <is_blank@plt>
cmp    $0x0,%rax
jne    116e <read_line+0x3e>
mov    -0x18(%rbp),%rdi
call   1040 <trim_line@plt>
mov    0x2e83(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_line>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
cmp    %rdi,0x2efc(%rip)
je     1160 <read_line+0x30>
mov    %rbp,0x2ef3(%rip)
movl   $0x0,0x2ef1(%rip)
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     1197 <read_line+0x67>
addl   $0x1,0x2ece(%rip)
mov    %rbx,%rdi
call   1050 <is_blank@plt>
test   %rax,%rax
jne    1160 <read_line+0x30>
mov    %rbx,%rdi
call   1040 <trim_line@plt>
mov    0x2eb3(%rip),%eax
jmp    1199 <read_line+0x69>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@read_line.current_fp = internal global i32* null
@read_line.current_line = internal global i32 0
define i32 @read_line(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32*, i32** %5
%9 = load i32*, i32** @read_line.current_fp
%10 = icmp ne i32* %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i32*, i32** %5
store i32* %12, i32** @read_line.current_fp
store i32 0, i32* @read_line.current_line
br label %13
13: ; preds = %11, %3
br label %14
14: ; preds = %24, %13
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = load i32*, i32** %5
%18 = call i32* @fgets(i8* %15, i32 %16, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 0, i32* %4
br label %32
21: ; preds = %14
%22 = load i32, i32* @read_line.current_line
%23 = add nsw i32 %22, 1
store i32 %23, i32* @read_line.current_line
br label %24
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = call i64 @is_blank(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %14, label %28
28: ; preds = %24
%29 = load i8*, i8** %6
%30 = call i32 @trim_line(i8* %29)
%31 = load i32, i32* @read_line.current_line
store i32 %31, i32* %4
br label %32
32: ; preds = %28, %20
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@read_line.current_fp = internal unnamed_addr global i32* null
@read_line.current_line = internal unnamed_addr global i32 0
define i32 @read_line(i32* %0, i8* %1, i32 %2) {
%4 = load i32*, i32** @read_line.current_fp
%5 = icmp eq i32* %4, %0
br i1 %5, label %7, label %6
6: ; preds = %3
store i32* %0, i32** @read_line.current_fp
store i32 0, i32* @read_line.current_line
br label %7
7: ; preds = %6, %3
br label %8
8: ; preds = %7, %11
%9 = tail call i32* @fgets(i8* %1, i32 %2, i32* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = load i32, i32* @read_line.current_line
%13 = add nsw i32 %12, 1
store i32 %13, i32* @read_line.current_line
%14 = tail call i64 @is_blank(i8* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %11
%17 = tail call i32 @trim_line(i8* %1)
%18 = load i32, i32* @read_line.current_line
br label %19
19: ; preds = %8, %16
%20 = phi i32 [ %18, %16 ], [ 0, %8 ]
ret i32 %20
}