#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 strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
const char *get_line(const char *content, char *line, int line_len) {
  const char *pos;
  int n;
  pos = strstr(content, "\n");
  if (pos) {
    n = pos - content;
    pos += 1;
  } else {
    n = strlen(content);
    pos = content + n;
  }
  if (n >= line_len)
    n = line_len - 1;
  strncpy(line, content, n);
  line[n] = 0;
  return pos;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1181 <get_line+0x51>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119c <get_line+0x6c>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11b1 <get_line+0x81>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     115c <get_line+0x2c>
mov    %rax,%rbx
sub    %r12d,%eax
add    $0x1,%rbx
jmp    116a <get_line+0x3a>
mov    %r12,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r12,%rbx
lea    -0x1(%r15),%ebp
cmp    %r15d,%eax
cmovl  %eax,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i8* @get_line(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i8* @strstr(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
store i32 %19, i32* %8
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %7
br label %29
22: ; preds = %3
%23 = load i8*, i8** %4
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %8
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %7
br label %29
29: ; preds = %22, %13
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %33, %29
%37 = load i8*, i8** %5
%38 = load i8*, i8** %4
%39 = load i32, i32* %8
%40 = call i32 @strncpy(i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %5
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %7
ret i8* %45
}

LLVM IR (-O2):
define i8* @get_line(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 10)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = ptrtoint i8* %4 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = getelementptr inbounds i8, i8* %4, i64 1
br label %16
12: ; preds = %3
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
br label %16
16: ; preds = %12, %6
%17 = phi i8* [ %11, %6 ], [ %15, %12 ]
%18 = phi i32 [ %10, %6 ], [ %13, %12 ]
%19 = icmp slt i32 %18, %2
%20 = add nsw i32 %2, -1
%21 = select i1 %19, i32 %18, i32 %20
%22 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %21)
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
ret i8* %17
}