#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 fgetc(int /*<<< orphan*/ *);
char *fgets(char *, size_t, int /*<<< orphan*/ *);
int strlen(char *);
int tokenize(char *, char *, int);
int tokenize_line(char *buffer, size_t n, int sep, FILE *fp) {
  char *p;
  int whole_line, ntok;
  p = fgets(buffer, n, fp);
  if (!p) {
    return -1;
  }
  if (!*p) {
    return 0;
  }
  whole_line = (buffer[strlen(buffer) - 1] == '\n');
  ntok = tokenize(buffer, buffer, sep);
  if (!whole_line) {
    while (fgetc(fp) != '\n') {
    }
  }
  return ntok;
}


x86 assembly (clang, -O0):
<tokenize_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1183 <tokenize_line+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <tokenize_line+0xd2>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119c <tokenize_line+0x5c>
movl   $0x0,-0x4(%rbp)
jmp    1212 <tokenize_line+0xd2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <tokenize@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    120c <tokenize_line+0xcc>
jmp    11ed <tokenize_line+0xad>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1207 <tokenize_line+0xc7>
jmp    11ed <tokenize_line+0xad>
jmp    120c <tokenize_line+0xcc>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rdi,%rbp
mov    %rcx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     119e <tokenize_line+0x5e>
cmpb   $0x0,(%rax)
je     11a5 <tokenize_line+0x65>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
mov    -0x1(%rax,%rbp,1),%r15b
mov    %rbp,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1060 <tokenize@plt>
mov    %eax,%ebp
cmp    $0xa,%r15b
je     11a7 <tokenize_line+0x67>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
jne    1190 <tokenize_line+0x50>
jmp    11a7 <tokenize_line+0x67>
mov    $0xffffffff,%ebp
jmp    11a7 <tokenize_line+0x67>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tokenize_line(i8* %0, i64 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%13 = load i8*, i8** %6
%14 = load i64, i64* %7
%15 = load i32*, i32** %9
%16 = call i8* @fgets(i8* %13, i64 %14, i32* %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %4
store i32 -1, i32* %5
br label %52
20: ; preds = %4
%21 = load i8*, i8** %10
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20
store i32 0, i32* %5
br label %52
25: ; preds = %20
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
%35 = zext i1 %34 to i32
store i32 %35, i32* %11
%36 = load i8*, i8** %6
%37 = load i8*, i8** %6
%38 = load i32, i32* %8
%39 = call i32 @tokenize(i8* %36, i8* %37, i32 %38)
store i32 %39, i32* %12
%40 = load i32, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %50, label %42
42: ; preds = %25
br label %43
43: ; preds = %48, %42
%44 = load i32*, i32** %9
%45 = call signext i8 @fgetc(i32* %44)
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 10
br i1 %47, label %48, label %49
48: ; preds = %43
br label %43
49: ; preds = %43
br label %50
50: ; preds = %49, %25
%51 = load i32, i32* %12
store i32 %51, i32* %5
br label %52
52: ; preds = %50, %24, %19
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
define i32 @tokenize_line(i8* %0, i64 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i8* @fgets(i8* %0, i64 %1, i32* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
%17 = tail call i32 @tokenize(i8* %0, i8* %0, i32 %2)
br i1 %16, label %21, label %18
18: ; preds = %10, %18
%19 = tail call signext i8 @fgetc(i32* %3)
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %18
21: ; preds = %18, %10, %7, %4
%22 = phi i32 [ -1, %4 ], [ 0, %7 ], [ %17, %10 ], [ %17, %18 ]
ret i32 %22
}