#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 sscanf(char const *, char *, char *);
char *strchr(char const *, char);
char *buf_getline(const char *from, char *to) {
  int ret;
  static int start_flag = 1;
  static const char *start;
  if (start_flag) {
    start_flag = 0;
    start = from;
  }
  if (start == NULL)
    return NULL;
  ret = sscanf(start, "%[^\n]", to);
  if (ret <= 0)
    return NULL;
  start = strchr(start, '\n');
  if (start != NULL)
    start++;
  return to;
}


x86 assembly (clang, -O0):
<buf_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,0x2ef9(%rip)
je     1152 <buf_getline+0x32>
movl   $0x0,0x2ee9(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,0x2eee(%rip)
cmpq   $0x0,0x2ee6(%rip)
jne    116d <buf_getline+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11de <buf_getline+0xbe>
mov    0x2ecc(%rip),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     119e <buf_getline+0x7e>
movq   $0x0,-0x8(%rbp)
jmp    11de <buf_getline+0xbe>
mov    0x2e9b(%rip),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,0x2e8a(%rip)
cmpq   $0x0,0x2e82(%rip)
je     11d6 <buf_getline+0xb6>
mov    0x2e75(%rip),%rax
add    $0x1,%rax
mov    %rax,0x2e6a(%rip)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buf_getline>:
push   %rbx
mov    %rsi,%rbx
cmpb   $0x0,0x2f0d(%rip)
je     113b <buf_getline+0x1b>
mov    0x2f0c(%rip),%rdi
test   %rdi,%rdi
jne    114e <buf_getline+0x2e>
jmp    1186 <buf_getline+0x66>
movb   $0x1,0x2ef6(%rip)
mov    %rdi,0x2ef7(%rip)
test   %rdi,%rdi
je     1186 <buf_getline+0x66>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdx
call   1040 <sscanf@plt>
test   %eax,%eax
jle    1186 <buf_getline+0x66>
mov    0x2ed8(%rip),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rax,%rcx
mov    %rcx,0x2ebc(%rip)
jmp    1188 <buf_getline+0x68>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@buf_getline.start_flag = internal global i32 1
@buf_getline.start = internal global i8* null
@.str = [6 x i8] c"%[^\0A]\00"
define i8* @buf_getline(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i32, i32* @buf_getline.start_flag
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
store i32 0, i32* @buf_getline.start_flag
%10 = load i8*, i8** %4
store i8* %10, i8** @buf_getline.start
br label %11
11: ; preds = %9, %2
%12 = load i8*, i8** @buf_getline.start
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i8* null, i8** %3
br label %32
15: ; preds = %11
%16 = load i8*, i8** @buf_getline.start
%17 = load i8*, i8** %5
%18 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i8* null, i8** %3
br label %32
22: ; preds = %15
%23 = load i8*, i8** @buf_getline.start
%24 = call i8* @strchr(i8* %23, i8 signext 10)
store i8* %24, i8** @buf_getline.start
%25 = load i8*, i8** @buf_getline.start
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** @buf_getline.start
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** @buf_getline.start
br label %30
30: ; preds = %27, %22
%31 = load i8*, i8** %5
store i8* %31, i8** %3
br label %32
32: ; preds = %30, %21, %14
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@buf_getline.start_flag = internal unnamed_addr global i1 false
@buf_getline.start = internal unnamed_addr global i8* null
@.str = [6 x i8] c"%[^\0A]\00"
define i8* @buf_getline(i8* %0, i8* %1) {
%3 = load i1, i1* @buf_getline.start_flag
br i1 %3, label %5, label %4
4: ; preds = %2
store i1 true, i1* @buf_getline.start_flag
store i8* %0, i8** @buf_getline.start
br label %7
5: ; preds = %2
%6 = load i8*, i8** @buf_getline.start
br label %7
7: ; preds = %5, %4
%8 = phi i8* [ %6, %5 ], [ %0, %4 ]
%9 = icmp eq i8* %8, null
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = tail call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%12 = icmp slt i32 %11, 1
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = load i8*, i8** @buf_getline.start
%15 = tail call i8* @strchr(i8* dereferenceable(1) %14, i8 signext 10)
%16 = icmp eq i8* %15, null
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = select i1 %16, i8* null, i8* %17
store i8* %18, i8** @buf_getline.start
br label %19
19: ; preds = %10, %7, %13
%20 = phi i8* [ %1, %13 ], [ null, %7 ], [ null, %10 ]
ret i8* %20
}