#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 /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *talloc(scalar_t__);
char *copy_rest_of_line(char *p) {
  char *s;
  for (s = p; *s && *s != '\n'; s++)
    ;
  *s = '\0';
  s = talloc(strlen(p) + 1);
  strcpy(s, p);
  return s;
}


x86 assembly (clang, -O0):
<copy_rest_of_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1169 <copy_rest_of_line+0x39>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1179 <copy_rest_of_line+0x49>
jmp    118f <copy_rest_of_line+0x5f>
jmp    117e <copy_rest_of_line+0x4e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <copy_rest_of_line+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <talloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_rest_of_line>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%rax
nopw   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     1152 <copy_rest_of_line+0x22>
cmp    $0xa,%cl
je     1152 <copy_rest_of_line+0x22>
add    $0x1,%rax
jmp    1140 <copy_rest_of_line+0x10>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <talloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @copy_rest_of_line(i8* %0) {
br label %2
2: ; preds = %5, %1
%3 = phi i8* [ %0, %1 ], [ %6, %5 ]
%4 = load i8, i8* %3
switch i8 %4, label %5 [
i8 0, label %7
i8 10, label %7
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
7: ; preds = %2, %2
store i8 0, i8* %3
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = add nsw i64 %8, 1
%10 = tail call i8* @talloc(i64 %9)
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
ret i8* %10
}