#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 */
void strip_carriage_return(char *string_to_be_stripped) {
  int length = 0;
  if (string_to_be_stripped == NULL)
    return;
  while (string_to_be_stripped[length] != '\0')
    length++;
  length--;
  if (string_to_be_stripped[length] == '\n')
    string_to_be_stripped[length] = '\0';
  return;
}


x86 assembly (clang, -O0):
<strip_carriage_return>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    111f <strip_carriage_return+0x1f>
jmp    1176 <strip_carriage_return+0x76>
jmp    1124 <strip_carriage_return+0x24>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1147 <strip_carriage_return+0x47>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1124 <strip_carriage_return+0x24>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1171 <strip_carriage_return+0x71>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1176 <strip_carriage_return+0x76>
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_carriage_return>:
test   %rdi,%rdi
je     113a <strip_carriage_return+0x3a>
movabs $0xfffffffe00000000,%rax
ff ff ff
movabs $0x100000000,%rcx
mov    %rdi,%rdx
nopl   0x0(%rax)
add    %rcx,%rax
cmpb   $0x0,(%rdx)
lea    0x1(%rdx),%rdx
jne    1120 <strip_carriage_return+0x20>
sar    $0x20,%rax
cmpb   $0xa,(%rdi,%rax,1)
jne    113a <strip_carriage_return+0x3a>
movb   $0x0,(%rdi,%rax,1)
ret

LLVM IR (-O0):
define void @strip_carriage_return(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
br label %35
7: ; preds = %1
br label %8
8: ; preds = %16, %7
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %34
29: ; preds = %19
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %29, %19
br label %35
35: ; preds = %34, %6
ret void
}

LLVM IR (-O2):
define void @strip_carriage_return(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1, %3
%4 = phi i64 [ %8, %3 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = shl i64 %4, 32
%11 = add i64 %10, -4294967296
%12 = ashr exact i64 %11, 32
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %9
store i8 0, i8* %13
br label %17
17: ; preds = %9, %16, %1
ret void
}