#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 */
struct timeval {
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ removeCarriageReturn(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void testRemoveCarriageReturn(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  char *buffer = malloc(sizeof(5));
  strcpy(buffer, "test\n");
  removeCarriageReturn(buffer);
  assert((strcmp(buffer, "test")) == 0);
  free(buffer);
  gettimeofday(&stop, NULL);
  printf("removeCarriageReturn success : %lu ms\n",
         stop.tv_usec - start.tv_usec);
}


x86 assembly (clang, -O0):
<testRemoveCarriageReturn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <removeCarriageReturn@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x8(%rbp),%rsi
sub    -0x10(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testRemoveCarriageReturn>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe5d(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   10a0 <removeCarriageReturn@plt>
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
sub    (%rsp),%rsi
lea    0xe17(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [6 x i8] c"test\0A\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [39 x i8] c"removeCarriageReturn success : %lu ms\0A\00"
define void @testRemoveCarriageReturn() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = alloca i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = call i8* @malloc(i32 4)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 @removeCarriageReturn(i8* %8)
%10 = load i8*, i8** %3
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = call i32 @free(i8* %15)
%17 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%21 = load i64, i64* %20
%22 = sub nsw i64 %19, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %22)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [6 x i8] c"test\0A\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [39 x i8] c"removeCarriageReturn success : %lu ms\0A\00"
define void @testRemoveCarriageReturn() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @removeCarriageReturn(i8* %6)
%9 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @free(i8* %6)
%14 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%18 = load i64, i64* %17
%19 = sub nsw i64 %16, %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %19)
ret void
}