#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*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char, int);
int /*<<< orphan*/ read(int, char *, int);
int main() {
  int fd = open("/dev/hello", O_RDONLY);
  char dt[100];
  read(fd, dt, 100);
  for (int i = 0; i < 100; i++) {
    printf("%c %d\n", dt[i], (int)(dt[i]));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x64,-0x74(%rbp)
jge    11aa <main+0x7a>
movslq -0x74(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
movslq -0x74(%rbp),%rcx
movsbl -0x70(%rbp,%rcx,1),%edx
lea    0xe77(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1172 <main+0x42>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0xeb9(%rip),%rdi
call   1050 <open@plt>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1040 <read@plt>
xor    %ebx,%ebx
lea    0xea7(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbx,1),%edx
mov    %r14,%rdi
mov    %edx,%esi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/hello\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"%c %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = call i32 @read(i32 %3, i8* %4, i32 100)
br label %7
6: ; preds = %7
ret i32 0
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %13, %7 ]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 signext %10, i32 %11)
%13 = add nuw nsw i64 %8, 1
%14 = icmp eq i64 %13, 100
br i1 %14, label %6, label %7
}