#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*/ free(char *);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
int main(void) {
  char array[11] = {};
  char *p = NULL;
  int i = 0, len;
  while ((array[i] = getchar()) != '\n')
    i++;
  array[i] = '\0';
  len = (int)strlen(array);
  p = (char *)malloc(sizeof(char) * len);
  for (i = 0; i < len; i++) {
    p[i] = array[i];
  }
  p[i] = '\0';
  puts(p);
  free(p);
  p = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xf(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1060 <memset@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
movslq -0x1c(%rbp),%rcx
mov    %al,-0xf(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11b7 <main+0x57>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <main+0x2e>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0xf(%rbp,%rax,1)
lea    -0xf(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1213 <main+0xb3>
movslq -0x1c(%rbp),%rax
mov    -0xf(%rbp,%rax,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e6 <main+0x86>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x7(%rsp)
movq   $0x0,(%rsp)
mov    $0xffffffffffffffff,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,0x1(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1180 <main+0x20>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %ebx,%ebx
jle    11c5 <main+0x65>
mov    %ebx,%r14d
mov    %rsp,%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1070 <memcpy@plt>
jmp    11c8 <main+0x68>
xor    %r14d,%r14d
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [11 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [11 x i8]* %2 to i8*
store i8* null, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %14, %0
%8 = call signext i8 (...) @getchar()
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %10
store i8 %8, i8* %11
%12 = sext i8 %8 to i32
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %7
17: ; preds = %7
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %3
store i32 0, i32* %4
br label %30
30: ; preds = %43, %17
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %34
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %30
46: ; preds = %30
%47 = load i8*, i8** %3
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %3
%52 = call i32 @puts(i8* %51)
%53 = load i8*, i8** %3
%54 = call i32 @free(i8* %53)
store i8* null, i8** %3
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [11 x i8]
%2 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ %9, %4 ], [ 0, %0 ]
%6 = tail call signext i8 (...) @getchar()
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 %5
store i8 %6, i8* %7
%8 = icmp eq i8 %6, 10
%9 = add nuw i64 %5, 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = and i64 %5, 4294967295
%12 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i64 @strlen(i8* %3)
%14 = trunc i64 %13 to i32
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = icmp sgt i32 %14, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = and i64 %13, 4294967295
%20 = and i64 %13, 4294967295
br label %21
21: ; preds = %18, %10
%22 = phi i64 [ 0, %10 ], [ %20, %18 ]
%23 = getelementptr inbounds i8, i8* %16, i64 %22
store i8 0, i8* %23
%24 = tail call i32 @puts(i8* dereferenceable(1) %16)
%25 = tail call i32 @free(i8* %16)
ret i32 0
}