#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 getchar();
int /*<<< orphan*/ my_strlen(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int main(void) {
  char str[1024] = {};
  int i = 0;
  while ((str[i] = getchar()) != '\n') {
    i++;
  }
  str[i] = '\0';
  puts(str);
  printf("%lu\n", my_strlen(str));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x414(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
movslq -0x414(%rbp),%rcx
mov    %al,-0x410(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11b4 <main+0x64>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    117f <main+0x2f>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1040 <puts@plt>
lea    -0x410(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%esi
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %al,0x1(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1170 <main+0x20>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <my_strlen@plt>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = bitcast [1024 x i8]* %2 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %12, %0
%6 = call signext i8 (...) @getchar()
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %8
store i8 %6, i8* %9
%10 = sext i8 %6 to i32
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %5
15: ; preds = %5
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = call i32 @puts(i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = call i32 @my_strlen(i8* %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ %8, %3 ], [ 0, %0 ]
%5 = tail call signext i8 (...) @getchar()
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %4
store i8 %5, i8* %6
%7 = icmp eq i8 %5, 10
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = and i64 %4, 4294967295
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @puts(i8* %2)
%13 = call i32 @my_strlen(i8* %2)
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
ret i32 0
}