#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 getchar();
char *strdup(char *);
char *input_str() {
  char buffer[4096];
  size_t i;
  for (i = 0; i < 4095; i++) {
    int c = getchar();
    if (c == '\n') {
      break;
    }
    buffer[i] = c;
  }
  buffer[i] = '\0';
  return (strdup(buffer));
}


x86 assembly (clang, -O0):
<input_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movq   $0x0,-0x1008(%rbp)
cmpq   $0xfff,-0x1008(%rbp)
jae    1193 <input_str+0x73>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x100c(%rbp)
cmpl   $0xa,-0x100c(%rbp)
jne    1166 <input_str+0x46>
jmp    1193 <input_str+0x73>
mov    -0x100c(%rbp),%eax
mov    %al,%cl
mov    -0x1008(%rbp),%rax
mov    %cl,-0x1000(%rbp,%rax,1)
mov    -0x1008(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1008(%rbp)
jmp    1136 <input_str+0x16>
mov    -0x1008(%rbp),%rax
movb   $0x0,-0x1000(%rbp,%rax,1)
lea    -0x1000(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_str>:
push   %rbx
sub    $0x1000,%rsp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     1151 <input_str+0x31>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xfff,%rbx
jne    1130 <input_str+0x10>
mov    $0xfff,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i8* @input_str() {
%1 = alloca [4096 x i8]
%2 = alloca i64
%3 = alloca i32
store i64 0, i64* %2
br label %4
4: ; preds = %17, %0
%5 = load i64, i64* %2
%6 = icmp ult i64 %5, 4095
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = call i32 (...) @getchar()
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %7
br label %20
12: ; preds = %7
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = load i64, i64* %2
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %15
store i8 %14, i8* %16
br label %17
17: ; preds = %12
%18 = load i64, i64* %2
%19 = add i64 %18, 1
store i64 %19, i64* %2
br label %4
20: ; preds = %11, %4
%21 = load i64, i64* %2
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%24 = call i8* @strdup(i8* %23)
ret i8* %24
}

LLVM IR (-O2):
define noalias i8* @input_str() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %7
%4 = phi i64 [ 0, %0 ], [ %10, %7 ]
%5 = tail call i32 (...) @getchar()
%6 = icmp eq i32 %5, 10
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = trunc i32 %5 to i8
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %4
store i8 %8, i8* %9
%10 = add nuw nsw i64 %4, 1
%11 = icmp eq i64 %10, 4095
br i1 %11, label %12, label %3
12: ; preds = %3, %7
%13 = phi i64 [ %4, %3 ], [ 4095, %7 ]
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i8* @strdup(i8* %2)
ret i8* %15
}