#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 */
typedef int ssize_t;

/* Variables and functions */
int read(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ sprintf(char *, char *, int, char);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  ssize_t amtRead;
  char buf[1000];
  while ((amtRead = read(0, buf, (size_t)1000)) > 0) {
    int i;
    for (i = 0; i < amtRead; i++) {
      char s[20];
      sprintf(s, "[%d]:<%c>\n", i, buf[i]);
      write(1, s, strlen(s));
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rsi
xor    %edi,%edi
mov    $0x3e8,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f8 <main+0xb8>
movl   $0x0,-0x3f4(%rbp)
mov    -0x3f4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f3 <main+0xb3>
lea    -0x410(%rbp),%rdi
mov    -0x3f4(%rbp),%edx
movslq -0x3f4(%rbp),%rax
lea    0xe5b(%rip),%rsi
movsbl -0x3f0(%rbp,%rax,1),%ecx
ff
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    117b <main+0x3b>
jmp    1152 <main+0x12>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0x20(%rsp),%rsi
mov    $0x3e8,%edx
xor    %edi,%edi
call   1050 <read@plt>
test   %eax,%eax
jle    11d5 <main+0x95>
lea    0xe94(%rip),%r14
mov    %rsp,%r12
lea    0x20(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x20(%rsp,%rbx,1),%ecx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1190 <main+0x50>
mov    $0x3e8,%edx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <read@plt>
test   %eax,%eax
jg     1180 <main+0x40>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"[%d]:<%c>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca [20 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %30, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 0, i8* %7, i64 1000)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %6
store i32 0, i32* %4
br label %11
11: ; preds = %27, %10
%12 = load i32, i32* %4
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17, i8 signext %21)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 1, i8* %23, i32 %25)
br label %27
27: ; preds = %15
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %11
30: ; preds = %11
br label %6
31: ; preds = %6
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [11 x i8] c"[%d]:<%c>\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = call i32 @read(i32 0, i8* %3, i64 1000)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %24
6: ; preds = %0
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
br label %11
8: ; preds = %14
%9 = call i32 @read(i32 0, i8* %3, i64 1000)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %8, %6
%12 = phi i32 [ %4, %6 ], [ %9, %8 ]
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %11, %14
%15 = phi i64 [ 0, %11 ], [ %22, %14 ]
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = trunc i64 %15 to i32
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18, i8 signext %17)
%20 = call i32 @strlen(i8* %7)
%21 = call i32 @write(i32 1, i8* %7, i32 %20)
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, %13
br i1 %23, label %8, label %14
24: ; preds = %8, %0
ret i32 0
}