#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 EOF;
char getchar();
int /*<<< orphan*/ printf(char *, char);
int main() {
  char c, line[100];
  int i, num = 0;
  while ((c = getchar()) != EOF) {
    line[num++] = c;
    if (c == '\n') {
      for (i = 0; i < 2 * num; ++i)
        printf("%c", line[i % num]);
      num = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x78(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e9b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c6 <main+0xa6>
mov    -0x5(%rbp),%cl
mov    -0x78(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x78(%rbp)
cltq
mov    %cl,-0x70(%rbp,%rax,1)
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    11c1 <main+0xa1>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    -0x78(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <main+0x9a>
mov    -0x74(%rbp),%eax
cltd
idivl  -0x78(%rbp)
movslq %edx,%rax
lea    0xe5e(%rip),%rdi
movsbl -0x70(%rbp,%rax,1),%esi
call   1030 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1180 <main+0x60>
movl   $0x0,-0x78(%rbp)
jmp    1139 <main+0x19>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eac(%rip),%r14
cmp    (%r14),%al
jne    1152 <main+0x32>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r15d
lea    0xea1(%rip),%r12
xor    %ecx,%ecx
jmp    1182 <main+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %r13d,%ecx
cmp    (%r14),%al
je     1141 <main+0x21>
lea    0x1(%rcx),%r13d
movslq %ecx,%rdx
mov    %al,(%rsp,%rdx,1)
cmp    $0xa,%al
jne    1173 <main+0x53>
test   %ecx,%ecx
js     1170 <main+0x50>
lea    0x0(%r13,%r13,1),%ebx
cmp    $0x2,%ebx
cmovl  %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
cltd
idiv   %r13d
movsbl (%rsp,%rdx,1),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    11b0 <main+0x90>
jmp    1170 <main+0x50>

LLVM IR (-O0):
@EOF = global i8 0
@.str = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
br label %6
6: ; preds = %39, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %2
%8 = sext i8 %7 to i32
%9 = load i8, i8* @EOF
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %40
12: ; preds = %6
%13 = load i8, i8* %2
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %16
store i8 %13, i8* %17
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %39
21: ; preds = %12
store i32 0, i32* %4
br label %22
22: ; preds = %35, %21
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = mul nsw i32 2, %24
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = srem i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %22
38: ; preds = %22
store i32 0, i32* %5
br label %39
39: ; preds = %38, %12
br label %6
40: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call signext i8 (...) @getchar()
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %32, label %6
6: ; preds = %0, %27
%7 = phi i8 [ %29, %27 ], [ %3, %0 ]
%8 = phi i32 [ %28, %27 ], [ 0, %0 ]
%9 = add nsw i32 %8, 1
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
store i8 %7, i8* %11
%12 = icmp eq i8 %7, 10
br i1 %12, label %13, label %27
13: ; preds = %6
%14 = icmp sgt i32 %8, -1
br i1 %14, label %15, label %27
15: ; preds = %13
%16 = shl nuw i32 %9, 1
%17 = call i32 @llvm.smax.i32(i32 %16, i32 1)
br label %18
18: ; preds = %15, %18
%19 = phi i32 [ %25, %18 ], [ 0, %15 ]
%20 = srem i32 %19, %9
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = add nuw nsw i32 %19, 1
%26 = icmp eq i32 %25, %17
br i1 %26, label %27, label %18
27: ; preds = %18, %13, %6
%28 = phi i32 [ %9, %6 ], [ 0, %13 ], [ 0, %18 ]
%29 = tail call signext i8 (...) @getchar()
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %32, label %6
32: ; preds = %27, %0
ret i32 0
}