#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 *calloc(int, int);
char *strchr(char *, char);
char *get_long_arg_from_pointer_malloc_ptr(char *start_ptr) {
  char *return_malloc_ptr =
      calloc((strchr(start_ptr, '\n') - start_ptr) + 1, 1);
  char *rolling_ptr = return_malloc_ptr;
  while (*start_ptr != '\n' && (*rolling_ptr++ = *start_ptr++))
    ;
  return return_malloc_ptr;
}


x86 assembly (clang, -O0):
<get_long_arg_from_pointer_malloc_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x19(%rbp)
je     11a0 <get_long_arg_from_pointer_malloc_ptr+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11b0 <get_long_arg_from_pointer_malloc_ptr+0x90>
jmp    11b5 <get_long_arg_from_pointer_malloc_ptr+0x95>
jmp    115d <get_long_arg_from_pointer_malloc_ptr+0x3d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long_arg_from_pointer_malloc_ptr>:
push   %rbx
mov    %rdi,%rbx
mov    $0xa,%esi
call   1030 <strchr@plt>
sub    %ebx,%eax
lea    0x1(%rax),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
xor    %ecx,%ecx
nop
movzbl (%rbx,%rcx,1),%edx
cmp    $0xa,%dl
je     1154 <get_long_arg_from_pointer_malloc_ptr+0x34>
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
test   %dl,%dl
jne    1140 <get_long_arg_from_pointer_malloc_ptr+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define i8* @get_long_arg_from_pointer_malloc_ptr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 10)
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %6 to i64
%9 = ptrtoint i8* %7 to i64
%10 = sub i64 %8, %9
%11 = add nsw i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i8* @calloc(i32 %12, i32 1)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
store i8* %14, i8** %4
br label %15
15: ; preds = %30, %1
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
%23 = load i8, i8* %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
store i8 %23, i8* %24
%26 = sext i8 %23 to i32
%27 = icmp ne i32 %26, 0
br label %28
28: ; preds = %20, %15
%29 = phi i1 [ false, %15 ], [ %27, %20 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %15
31: ; preds = %28
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define noalias i8* @get_long_arg_from_pointer_malloc_ptr(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%3 = ptrtoint i8* %2 to i64
%4 = ptrtoint i8* %0 to i64
%5 = sub i64 %3, %4
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 1
%8 = tail call i8* @calloc(i32 %7, i32 1)
br label %9
9: ; preds = %14, %1
%10 = phi i8* [ %0, %1 ], [ %15, %14 ]
%11 = phi i8* [ %8, %1 ], [ %16, %14 ]
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 10
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %12, i8* %11
%17 = icmp eq i8 %12, 0
br i1 %17, label %18, label %9
18: ; preds = %9, %14
ret i8* %8
}