#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *get_input() {
  char *input = malloc(1000 * sizeof(char));
  if (fgets(input, 1000 * sizeof(char), stdin) != 0) {
    size_t last_char = strlen(input) - 1;
    if (input[last_char] == '\n') {
      input[last_char] = '\0';
    }
  } else {
    input = NULL;
  }
  return input;
}


x86 assembly (clang, -O0):
<get_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     119f <get_input+0x6f>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    119a <get_input+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a7 <get_input+0x77>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

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

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

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