#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*/ printf(char *, ...);
int main() {
  char array[4], temp = '0';
  int n = 0;
  printf("\n------\n");
  while (temp != '\n' && n < 4) {
    temp = getchar();
    array[n] = temp;
    n++;
    printf("#%d %c\n", n, temp);
  }
  for (n = 0; n < 4; n++) {
    printf("%c", array[n]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x30,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x9(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x11(%rbp)
je     1164 <main+0x44>
cmpl   $0x4,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1174 <main+0x54>
jmp    11ac <main+0x8c>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x8(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
movsbl -0x9(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1148 <main+0x28>
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11e2 <main+0xc2>
movslq -0x10(%rbp),%rax
movsbl -0x8(%rbp,%rax,1),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b3 <main+0x93>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,0x4(%rsp,%rbp,1)
lea    0x1(%rbp),%rbx
movsbl %al,%r15d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xa,%r15b
je     1191 <main+0x51>
cmp    $0x3,%rbp
mov    %rbx,%rbp
jb     1160 <main+0x20>
movsbl 0x4(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x5(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x6(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [8 x i8] c"#%d %c\0A\00"
@str = [8 x i8] c"\0A------\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %8, %4 ]
%6 = tail call signext i8 (...) @getchar()
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 %5
store i8 %6, i8* %7
%8 = add nuw nsw i64 %5, 1
%9 = sext i8 %6 to i32
%10 = trunc i64 %8 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %9)
%12 = icmp ne i8 %6, 10
%13 = icmp ult i64 %5, 3
%14 = and i1 %12, %13
br i1 %14, label %4, label %15
15: ; preds = %4
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
%18 = tail call i32 @putchar(i32 %17)
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = tail call i32 @putchar(i32 %21)
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = tail call i32 @putchar(i32 %25)
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 @putchar(i32 %29)
%31 = tail call i32 @putchar(i32 10)
ret i32 0
}