#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 */
char *strchr(char *, char);
void m_strip_newline(char **input) {
  if (*input == NULL)
    return;
  char *newline = strchr((*input), '\r');
  if (newline == NULL)
    newline = strchr(*input, '\n');
  if (newline != NULL)
    (*input)[newline - *input] = '\0';
}


x86 assembly (clang, -O0):
<m_strip_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    112f <m_strip_newline+0x1f>
jmp    1188 <m_strip_newline+0x78>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <m_strip_newline+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1188 <m_strip_newline+0x78>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_strip_newline>:
push   %rbx
mov    (%rdi),%rbx
test   %rbx,%rbx
je     1140 <m_strip_newline+0x30>
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    113d <m_strip_newline+0x2d>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1140 <m_strip_newline+0x30>
movb   $0x0,(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @m_strip_newline(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i8* @strchr(i8* %2, i8 signext 13)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i8* @strchr(i8* %2, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %4, %7
%11 = phi i8* [ %8, %7 ], [ %5, %4 ]
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %2 to i64
%14 = sub i64 %12, %13
%15 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %7, %10, %1
ret void
}