#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 */

/* Variables and functions */
int /*<<< orphan*/ TrimSpace(char *);
int /*<<< orphan*/ isEndOfLine(char **);
void ExtractLine(char *buf, int buflen, char **p) {
  int bufp = 0;
  while (!isEndOfLine(p)) {
    if (bufp < buflen - 1) {
      buf[bufp++] = **p;
    }
    (*p)++;
  }
  buf[bufp++] = 0;
  TrimSpace(buf);
}


x86 assembly (clang, -O0):
<ExtractLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <isEndOfLine@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1158 <ExtractLine+0x38>
jmp    119a <ExtractLine+0x7a>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1187 <ExtractLine+0x67>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    113a <ExtractLine+0x1a>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1040 <TrimSpace@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExtractLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <isEndOfLine@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1158 <ExtractLine+0x38>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <TrimSpace@plt>
add    $0xffffffff,%r15d
xor    %ebp,%ebp
jmp    1170 <ExtractLine+0x50>
addq   $0x1,(%rbx)
mov    %rbx,%rdi
call   1030 <isEndOfLine@plt>
test   %eax,%eax
jne    113e <ExtractLine+0x1e>
cmp    %r15d,%ebp
jge    1160 <ExtractLine+0x40>
mov    (%rbx),%rax
movzbl (%rax),%eax
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
jmp    1160 <ExtractLine+0x40>

LLVM IR (-O0):
define void @ExtractLine(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i32 0, i32* %7
br label %8
8: ; preds = %27, %3
%9 = load i8**, i8*** %6
%10 = call i32 @isEndOfLine(i8** %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = load i32, i32* %7
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
br label %27
27: ; preds = %18, %13
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %28
br label %8
31: ; preds = %8
%32 = load i8*, i8** %4
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
store i8 0, i8* %36
%37 = load i8*, i8** %4
%38 = call i32 @TrimSpace(i8* %37)
ret void
}

LLVM IR (-O2):
define void @ExtractLine(i8* %0, i32 %1, i8** %2) {
%4 = tail call i32 @isEndOfLine(i8** %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = add nsw i32 %1, -1
br label %8
8: ; preds = %6, %17
%9 = phi i32 [ 0, %6 ], [ %18, %17 ]
%10 = icmp slt i32 %9, %7
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = add nsw i32 %9, 1
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %13, i8* %16
br label %17
17: ; preds = %11, %8
%18 = phi i32 [ %14, %11 ], [ %9, %8 ]
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %2
%21 = tail call i32 @isEndOfLine(i8** %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %8, label %23
23: ; preds = %17, %3
%24 = phi i32 [ 0, %3 ], [ %18, %17 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 0, i8* %26
%27 = tail call i32 @TrimSpace(i8* %0)
ret void
}