#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*/ free(char *);
char *malloc(unsigned int);
char *strdup(char *);
unsigned int strlen(char *);
char *Strip(char *s) {
  char *dup_s = strdup(s);
  unsigned int len_dup_s = strlen(dup_s);
  char *new_s = malloc((len_dup_s + 2) * sizeof(char));
  unsigned int i = 0;
  for (i = 0; i < strlen(dup_s); i++) {
    if (dup_s[i] == '\n') {
      new_s[i] = '\0';
      break;
    }
    new_s[i] = dup_s[i];
  }
  free(dup_s);
  return new_s;
}


x86 assembly (clang, -O0):
<Strip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    11ec <Strip+0xac>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ca <Strip+0x8a>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    11ec <Strip+0xac>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <Strip+0x4a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Strip>:
push   %r15
push   %r14
push   %rbx
call   1060 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1197 <Strip+0x57>
xor    %ebx,%ebx
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%eax
cmp    $0xa,%al
je     1192 <Strip+0x52>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1170 <Strip+0x30>
jmp    1197 <Strip+0x57>
movb   $0x0,(%r14,%rbx,1)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define noalias i8* @Strip(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = add i32 %3, 2
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @strlen(i8* %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1, %16
%9 = phi i64 [ %18, %16 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = and i64 %9, 4294967295
%15 = getelementptr inbounds i8, i8* %5, i64 %14
store i8 0, i8* %15
br label %22
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 %11, i8* %17
%18 = add nuw nsw i64 %9, 1
%19 = tail call i32 @strlen(i8* %2)
%20 = zext i32 %19 to i64
%21 = icmp ult i64 %18, %20
br i1 %21, label %8, label %22
22: ; preds = %16, %1, %13
%23 = tail call i32 @free(i8* %2)
ret i8* %5
}