#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_next_line(const char **pp) {
  const char *p = *pp;
  char *q, tmpbuf[1024];
  q = tmpbuf;
  while (*p && (*p != '\n') && q < tmpbuf + sizeof(tmpbuf) - 1)
    *q++ = *p++;
  *q = 0;
  *pp = p;
  return strdup(tmpbuf);
}


x86 assembly (clang, -O0):
<dup_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
je     1187 <dup_next_line+0x77>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x421(%rbp)
je     1187 <dup_next_line+0x77>
mov    -0x18(%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    119a <dup_next_line+0x8a>
jmp    11c1 <dup_next_line+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1135 <dup_next_line+0x25>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%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_next_line>:
sub    $0x408,%rsp
mov    (%rdi),%rax
mov    (%rax),%dl
mov    %rsp,%rcx
test   %dl,%dl
je     114c <dup_next_line+0x3c>
lea    0x3ff(%rsp),%rsi
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%dl
je     114c <dup_next_line+0x3c>
cmp    %rsi,%rcx
jae    114c <dup_next_line+0x3c>
mov    %dl,(%rcx)
add    $0x1,%rcx
movzbl 0x1(%rax),%edx
add    $0x1,%rax
test   %dl,%dl
jne    1130 <dup_next_line+0x20>
movb   $0x0,(%rcx)
mov    %rax,(%rdi)
mov    %rsp,%rdi
call   1030 <strdup@plt>
add    $0x408,%rsp
ret

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

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