#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 */
char *strchr(char *, char);
void readline(char **start, char **end, char *buf) {
  *start = *end;
  *end = strchr(*start, '\n');
  if (!*end) {
    *start = NULL;
    return;
  }
  while (*start != *end) {
    *buf = **start;
    *start += 1;
    buf += 1;
  }
  *buf = '\0';
  *end += 1;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116b <readline+0x5b>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    11c7 <readline+0xb7>
jmp    1170 <readline+0x60>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
je     11b2 <readline+0xa2>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1170 <readline+0x60>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rdi
mov    %rdi,(%r15)
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1161 <readline+0x51>
mov    (%r15),%rcx
cmp    %rax,%rcx
je     1158 <readline+0x48>
xchg   %ax,%ax
movzbl (%rcx),%eax
mov    %al,(%rbx)
mov    (%r15),%rcx
add    $0x1,%rcx
mov    %rcx,(%r15)
add    $0x1,%rbx
cmp    (%r14),%rcx
jne    1140 <readline+0x30>
movb   $0x0,(%rbx)
addq   $0x1,(%r14)
jmp    1168 <readline+0x58>
movq   $0x0,(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @readline(i8** nocapture %0, i8** nocapture %1, i8* nocapture writeonly %2) {
%4 = load i8*, i8** %1
store i8* %4, i8** %0
%5 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 10)
store i8* %5, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = load i8*, i8** %0
%9 = icmp eq i8* %8, %5
br i1 %9, label %20, label %11
10: ; preds = %3
store i8* null, i8** %0
br label %24
11: ; preds = %7, %11
%12 = phi i8* [ %16, %11 ], [ %8, %7 ]
%13 = phi i8* [ %17, %11 ], [ %2, %7 ]
%14 = load i8, i8* %12
store i8 %14, i8* %13
%15 = load i8*, i8** %0
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %0
%17 = getelementptr inbounds i8, i8* %13, i64 1
%18 = load i8*, i8** %1
%19 = icmp eq i8* %16, %18
br i1 %19, label %20, label %11
20: ; preds = %11, %7
%21 = phi i8* [ %2, %7 ], [ %17, %11 ]
store i8 0, i8* %21
%22 = load i8*, i8** %1
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %1
br label %24
24: ; preds = %20, %10
ret void
}