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

/* Variables and functions */
char *strdup(char *);
char *dup_line_until(const char **pp, char until) {
  const char *p = *pp;
  char *q, tmpbuf[1024];
  q = tmpbuf;
  while (*p && (*p != '\n') && (*p != until) && q < tmpbuf + sizeof(tmpbuf) - 1)
    *q++ = *p++;
  *q = 0;
  *pp = p;
  return strdup(tmpbuf);
}


x86 assembly (clang, -O0):
<dup_line_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
je     11a8 <dup_line_until+0x98>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x421(%rbp)
je     11a8 <dup_line_until+0x98>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x9(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x421(%rbp)
je     11a8 <dup_line_until+0x98>
mov    -0x20(%rbp),%rax
lea    -0x420(%rbp),%rcx
add    $0x400,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    11bb <dup_line_until+0xab>
jmp    11e2 <dup_line_until+0xd2>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    113b <dup_line_until+0x2b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x420(%rbp),%rdi
call   1030 <strdup@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_line_until>:
sub    $0x408,%rsp
mov    (%rdi),%rax
mov    %rsp,%rcx
lea    0x3ff(%rsp),%r8
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rax),%edx
test   %dl,%dl
je     1152 <dup_line_until+0x42>
cmp    $0xa,%dl
je     1152 <dup_line_until+0x42>
cmp    %sil,%dl
je     1152 <dup_line_until+0x42>
cmp    %r8,%rcx
jae    1152 <dup_line_until+0x42>
add    $0x1,%rax
mov    %dl,(%rcx)
add    $0x1,%rcx
jmp    1130 <dup_line_until+0x20>
movb   $0x0,(%rcx)
mov    %rax,(%rdi)
mov    %rsp,%rdi
call   1030 <strdup@plt>
add    $0x408,%rsp
ret

LLVM IR (-O0):
define i8* @dup_line_until(i8** %0, i8 signext %1) {
%3 = alloca i8**
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
store i8** %0, i8*** %3
store i8 %1, i8* %4
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
store i8* %9, i8** %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %10, i8** %6
br label %11
11: ; preds = %36, %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %34
28: ; preds = %21
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 1024
%32 = getelementptr inbounds i8, i8* %31, i64 -1
%33 = icmp ult i8* %29, %32
br label %34
34: ; preds = %28, %21, %16, %11
%35 = phi i1 [ false, %21 ], [ false, %16 ], [ false, %11 ], [ %33, %28 ]
br i1 %35, label %36, label %42
36: ; preds = %34
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
%39 = load i8, i8* %37
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %6
store i8 %39, i8* %40
br label %11
42: ; preds = %34
%43 = load i8*, i8** %6
store i8 0, i8* %43
%44 = load i8*, i8** %5
%45 = load i8**, i8*** %3
store i8* %44, i8** %45
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = call i8* @strdup(i8* %46)
ret i8* %47
}

LLVM IR (-O2):
define noalias i8* @dup_line_until(i8** nocapture %0, i8 signext %1) {
%3 = alloca [1024 x i8]
%4 = load i8*, i8** %0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
br label %7
7: ; preds = %15, %2
%8 = phi i8* [ %4, %2 ], [ %16, %15 ]
%9 = phi i8* [ %5, %2 ], [ %17, %15 ]
%10 = load i8, i8* %8
switch i8 %10, label %11 [
i8 0, label %18
i8 10, label %18
]
11: ; preds = %7
%12 = icmp ne i8 %10, %1
%13 = icmp ult i8* %9, %6
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %10, i8* %9
br label %7
18: ; preds = %7, %7, %11
store i8 0, i8* %9
store i8* %8, i8** %0
%19 = call i8* @strdup(i8* %5)
ret i8* %19
}