#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 *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *get_input(char *input) {
  printf("> ");
  char *ret = fgets(input, 1000, stdin);
  if (ret == NULL) {
    return ret;
  }
  int len = strlen(input) - 1;
  if (input[len] == '\n') {
    input[len] = '\0';
  }
  return input;
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <get_input+0x4b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <get_input+0x83>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ab <get_input+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1173 <get_input+0x43>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1175 <get_input+0x45>
movb   $0x0,-0x1(%rbx,%rax,1)
jmp    1175 <get_input+0x45>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
define i8* @get_input(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = load i32, i32* @stdin
%9 = call i8* @fgets(i8* %7, i32 1000, i32 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %4
store i8* %13, i8** %2
br label %32
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %5
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %30
25: ; preds = %14
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %25, %14
%31 = load i8*, i8** %3
store i8* %31, i8** %2
br label %32
32: ; preds = %30, %12
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@stdin = global i32 0
define i8* @get_input(i8* %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i8* @fgets(i8* %0, i32 1000, i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %6
store i8 0, i8* %10
br label %14
14: ; preds = %6, %13, %1
%15 = phi i8* [ null, %1 ], [ %0, %13 ], [ %0, %6 ]
ret i8* %15
}