#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 */
char *fgets0(char *, int, int /*<<< orphan*/ *);
scalar_t__ isemptyline(char *);
char *getnextline(char *buf, int s, FILE *f, int *line) {
  char *p;
  int l = 0;
  do {
    p = fgets0(buf, s, f);
    line[0]++;
  } while (p && isemptyline(buf));
  if (p == NULL || isemptyline(p))
    return (NULL);
  else
    return (p);
}


x86 assembly (clang, -O0):
<getnextline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <fgets0@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
xor    %eax,%eax
cmpq   $0x0,-0x30(%rbp)
mov    %al,-0x35(%rbp)
je     1180 <getnextline+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <isemptyline@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    113e <getnextline+0x1e>
cmpq   $0x0,-0x30(%rbp)
je     11a9 <getnextline+0x89>
mov    -0x30(%rbp),%rdi
call   1030 <isemptyline@plt>
cmp    $0x0,%rax
je     11b6 <getnextline+0x96>
movq   $0x0,-0x8(%rbp)
jmp    11be <getnextline+0x9e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnextline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%r13d
mov    %rdi,%rbp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %r12,%rdx
call   1040 <fgets0@plt>
addl   $0x1,(%r15)
test   %rax,%rax
je     1179 <getnextline+0x59>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <isemptyline@plt>
test   %rax,%rax
jne    1140 <getnextline+0x20>
mov    %rbx,%rdi
call   1030 <isemptyline@plt>
xor    %r14d,%r14d
test   %rax,%rax
cmove  %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getnextline(i8* %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %11
br label %12
12: ; preds = %28, %4
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = load i32*, i32** %8
%16 = call i8* @fgets0(i8* %13, i32 %14, i32* %15)
store i8* %16, i8** %10
%17 = load i32*, i32** %9
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %18
br label %21
21: ; preds = %12
%22 = load i8*, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = call i64 @isemptyline(i8* %25)
%27 = icmp ne i64 %26, 0
br label %28
28: ; preds = %24, %21
%29 = phi i1 [ false, %21 ], [ %27, %24 ]
br i1 %29, label %12, label %30
30: ; preds = %28
%31 = load i8*, i8** %10
%32 = icmp eq i8* %31, null
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i8*, i8** %10
%35 = call i64 @isemptyline(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33, %30
store i8* null, i8** %5
br label %40
38: ; preds = %33
%39 = load i8*, i8** %10
store i8* %39, i8** %5
br label %40
40: ; preds = %38, %37
%41 = load i8*, i8** %5
ret i8* %41
}

LLVM IR (-O2):
define i8* @getnextline(i8* %0, i32 %1, i32* %2, i32* nocapture %3) {
br label %5
5: ; preds = %10, %4
%6 = tail call i8* @fgets0(i8* %0, i32 %1, i32* %2)
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
store i32 %8, i32* %3
%9 = icmp eq i8* %6, null
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = tail call i64 @isemptyline(i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %5
13: ; preds = %10
%14 = tail call i64 @isemptyline(i8* %6)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* %6, i8* null
br label %17
17: ; preds = %5, %13
%18 = phi i8* [ %16, %13 ], [ null, %5 ]
ret i8* %18
}