#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int getInput(char *str) {
  char *ptr;
  if (fgets(str, 8192, stdin) == NULL)
    return 0;
  ptr = strchr(str, '\n');
  if (ptr != NULL)
    *ptr = '\0';
  ptr = strchr(str, '\r');
  if (ptr != NULL)
    *ptr = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<getInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1159 <getInput+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <getInput+0x88>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117d <getInput+0x5d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a1 <getInput+0x81>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInput>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ebd(%rip),%rax
mov    (%rax),%edx
mov    $0x2000,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1170 <getInput+0x50>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1151 <getInput+0x31>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     116e <getInput+0x4e>
movb   $0x0,(%rcx)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @getInput(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %5, i32 8192, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %25
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i8*, i8** %4
store i8 0, i8* %16
br label %17
17: ; preds = %15, %10
%18 = load i8*, i8** %3
%19 = call i8* @strchr(i8* %18, i8 signext 13)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i8*, i8** %4
store i8 0, i8* %23
br label %24
24: ; preds = %22, %17
store i32 1, i32* %2
br label %25
25: ; preds = %24, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @getInput(i8* %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32* @fgets(i8* %0, i32 8192, i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %5
store i8 0, i8* %6
br label %9
9: ; preds = %8, %5
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 13)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8 0, i8* %10
br label %13
13: ; preds = %9, %12, %1
%14 = phi i32 [ 0, %1 ], [ 1, %12 ], [ 1, %9 ]
ret i32 %14
}