#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 /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ read(int, int *, int);
int main4(int argc, char **argv) {
  int fd;
  int c;
  fd = open(argv[1], O_RDONLY);
  while (read(fd, &c, 1) > 0) {
    printf("%c ", c);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1197 <main4+0x57>
mov    -0x18(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    1168 <main4+0x28>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main4>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11a0 <main4+0x60>
lea    0xe86(%rip),%r14
lea    0xc(%rsp),%r15
nop
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1180 <main4+0x40>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <close@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [4 x i8] c"%c \00"
define i32 @main4(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
br label %13
13: ; preds = %17, %2
%14 = load i32, i32* %6
%15 = call i64 @read(i32 %14, i32* %7, i32 1)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %7
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %13
20: ; preds = %13
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [4 x i8] c"%c \00"
define i32 @main4(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = call i64 @read(i32 %8, i32* %3, i32 1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2, %11
%12 = load i32, i32* %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i64 @read(i32 %8, i32* %3, i32 1)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %11, %2
%17 = tail call i32 @close(i32 %8)
ret i32 undef
}