#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 */
size_t strlen(char *);
char *RemoveNL(char *p) {
  if (p) {
    size_t l = strlen(p);
    while (l > 0 && (p[l - 1] == '\n')) {
      p[--l] = 0;
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<RemoveNL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118f <RemoveNL+0x7f>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jbe    115d <RemoveNL+0x4d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    116d <RemoveNL+0x5d>
jmp    118a <RemoveNL+0x7a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
movb   $0x0,-0x1(%rax,%rcx,1)
jmp    1134 <RemoveNL+0x24>
jmp    118f <RemoveNL+0x7f>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RemoveNL>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1142 <RemoveNL+0x32>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1142 <RemoveNL+0x32>
cs nopw 0x0(%rax,%rax,1)
cmpb   $0xa,-0x1(%rbx,%rax,1)
jne    1142 <RemoveNL+0x32>
movb   $0x0,-0x1(%rbx,%rax,1)
add    $0xffffffffffffffff,%rax
jne    1130 <RemoveNL+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

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