#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 *ft_strchr(char *, char);
int /*<<< orphan*/ ft_strclr(char *);
int /*<<< orphan*/ ft_strdel(char **);
char *ft_strdup(char *);
scalar_t__ ft_strlen(char *);
char *ft_strsub(char *, int /*<<< orphan*/, scalar_t__);
char *get_line(char *offset, char **line) {
  char *tmp;
  char *del;
  del = offset;
  if (offset && (tmp = ft_strchr(offset, '\n'))) {
    *line = ft_strsub(offset, 0, ft_strlen(offset) - ft_strlen(tmp));
    offset = ft_strdup(tmp + 1);
    ft_strdel(&del);
  } else {
    *line = ft_strdup(offset);
    ft_strclr(offset);
  }
  return (offset);
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f8 <get_line+0x98>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1080 <ft_strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f8 <get_line+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ft_strlen@plt>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rdi
sub    %rax,%rdx
xor    %esi,%esi
call   1050 <ft_strsub@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <ft_strdup@plt>
mov    %rax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <ft_strdel@plt>
jmp    1214 <get_line+0xb4>
mov    -0x8(%rbp),%rdi
call   1070 <ft_strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strclr@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,(%rsp)
test   %rdi,%rdi
je     11cb <get_line+0x6b>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <ft_strchr@plt>
test   %rax,%rax
je     11cb <get_line+0x6b>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <ft_strlen@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <ft_strlen@plt>
sub    %rax,%r12
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1050 <ft_strsub@plt>
mov    %rax,(%r14)
add    $0x1,%r15
mov    %r15,%rdi
call   1070 <ft_strdup@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1060 <ft_strdel@plt>
jmp    11de <get_line+0x7e>
mov    %rbx,%rdi
call   1070 <ft_strdup@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1030 <ft_strclr@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @get_line(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i8* @ft_strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8*, i8** %3
%17 = call i64 @ft_strlen(i8* %16)
%18 = load i8*, i8** %5
%19 = call i64 @ft_strlen(i8* %18)
%20 = sub nsw i64 %17, %19
%21 = call i8* @ft_strsub(i8* %15, i32 0, i64 %20)
%22 = load i8**, i8*** %4
store i8* %21, i8** %22
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i8* @ft_strdup(i8* %24)
store i8* %25, i8** %3
%26 = call i32 @ft_strdel(i8** %6)
br label %33
27: ; preds = %10, %2
%28 = load i8*, i8** %3
%29 = call i8* @ft_strdup(i8* %28)
%30 = load i8**, i8*** %4
store i8* %29, i8** %30
%31 = load i8*, i8** %3
%32 = call i32 @ft_strclr(i8* %31)
br label %33
33: ; preds = %27, %14
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
define i8* @get_line(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = icmp eq i8* %0, null
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = tail call i8* @ft_strchr(i8* %0, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i64 @ft_strlen(i8* %0)
%11 = tail call i64 @ft_strlen(i8* %7)
%12 = sub nsw i64 %10, %11
%13 = tail call i8* @ft_strsub(i8* %0, i32 0, i64 %12)
store i8* %13, i8** %1
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = tail call i8* @ft_strdup(i8* %14)
%16 = call i32 @ft_strdel(i8** %3)
br label %20
17: ; preds = %6, %2
%18 = tail call i8* @ft_strdup(i8* %0)
store i8* %18, i8** %1
%19 = tail call i32 @ft_strclr(i8* %0)
br label %20
20: ; preds = %17, %9
%21 = phi i8* [ %15, %9 ], [ %0, %17 ]
ret i8* %21
}