#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 length_before_newline(char *);
char *malloc(int);
char *get_line(char **str) {
  int i;
  int len;
  char *temp;
  len = length_before_newline(*str);
  temp = malloc(sizeof(char) * (len + 1));
  i = 0;
  while (**str != '\n' && **str != '\0') {
    temp[i] = **str;
    (*str)++;
    i++;
  }
  temp[i] = '\0';
  return (temp);
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <length_before_newline@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     1184 <get_line+0x64>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1194 <get_line+0x74>
jmp    11c4 <get_line+0xa4>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <get_line+0x39>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1030 <length_before_newline@plt>
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    (%r14),%rcx
add    $0x1,%rcx
xor    %edx,%edx
movzbl -0x1(%rcx),%ebx
test   %bl,%bl
je     115d <get_line+0x3d>
cmp    $0xa,%bl
je     115d <get_line+0x3d>
mov    %bl,(%rax,%rdx,1)
mov    %rcx,(%r14)
add    $0x1,%rdx
add    $0x1,%rcx
jmp    1140 <get_line+0x20>
mov    %edx,%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_line(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8** %0, i8*** %2
%6 = load i8**, i8*** %2
%7 = load i8*, i8** %6
%8 = call i32 @length_before_newline(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 1, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %5
store i32 0, i32* %3
br label %15
15: ; preds = %29, %1
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i8**, i8*** %2
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br label %27
27: ; preds = %21, %15
%28 = phi i1 [ false, %15 ], [ %26, %21 ]
br i1 %28, label %29, label %42
29: ; preds = %27
%30 = load i8**, i8*** %2
%31 = load i8*, i8** %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %5
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
%37 = load i8**, i8*** %2
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %37
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %15
42: ; preds = %27
%43 = load i8*, i8** %5
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %5
ret i8* %47
}

LLVM IR (-O2):
define noalias i8* @get_line(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @length_before_newline(i8* %2)
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = load i8*, i8** %0
br label %7
7: ; preds = %11, %1
%8 = phi i8* [ %13, %11 ], [ %6, %1 ]
%9 = phi i64 [ %14, %11 ], [ 0, %1 ]
%10 = load i8, i8* %8
switch i8 %10, label %11 [
i8 10, label %15
i8 0, label %15
]
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %10, i8* %12
%13 = getelementptr inbounds i8, i8* %8, i64 1
store i8* %13, i8** %0
%14 = add nuw i64 %9, 1
br label %7
15: ; preds = %7, %7
%16 = and i64 %9, 4294967295
%17 = getelementptr inbounds i8, i8* %5, i64 %16
store i8 0, i8* %17
ret i8* %5
}