#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 strlen(char *);
char *RemoveNL(char *s) {
  register char *t;
  if (!s)
    return (s);
  if ((t = s + strlen(s) - 1) < s)
    return (s);
  if (*t == '\n')
    *t = '\0';
  return (s);
}


x86 assembly (clang, -O0):
<RemoveNL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <RemoveNL+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <RemoveNL+0x7f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmp    -0x10(%rbp),%rax
jae    1170 <RemoveNL+0x60>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <RemoveNL+0x7f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1187 <RemoveNL+0x77>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RemoveNL>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1137 <RemoveNL+0x27>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jb     1137 <RemoveNL+0x27>
cmpb   $0xa,(%rax)
jne    1137 <RemoveNL+0x27>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @RemoveNL(i8* returned %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = icmp ult i8* %7, %0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %13
12: ; preds = %9
store i8 0, i8* %7
br label %13
13: ; preds = %9, %12, %3, %1
ret i8* %0
}