#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 /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char *name;
  if (argc != 2) {
    printf("usage: file FILENAME\n");
    exit(1);
  } else {
    name = argv[1];
  }
  if (0 > (fd = open(name, O_RDONLY, 0)))
    exit(1);
  {
    char buf[5];
    int n;
    while (0 < (n = read(fd, buf, 5))) {
      write(1, buf, n);
    }
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1196 <main+0x36>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jle    11cf <main+0x6f>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d4 <main+0x74>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0x5,%edx
call   1060 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jge    120a <main+0xaa>
lea    -0x25(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11d4 <main+0x74>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11d2 <main+0x72>
mov    0x8(%rsi),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11de <main+0x7e>
mov    %eax,%ebp
lea    0x3(%rsp),%rsi
mov    %eax,%edi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11c2 <main+0x62>
lea    0x3(%rsp),%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11a0 <main+0x40>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"usage: file FILENAME\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [5 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %7
br label %19
19: ; preds = %15
%20 = load i8*, i8** %7
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21, i32 0)
store i32 %22, i32* %6
%23 = icmp sgt i32 0, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
br label %27
27: ; preds = %32, %26
%28 = load i32, i32* %6
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 5)
store i32 %30, i32* %9
%31 = icmp slt i32 0, %30
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* %9
%35 = call i32 @write(i32 1, i8* %33, i32 %34)
br label %27
36: ; preds = %27
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@str = [21 x i8] c"usage: file FILENAME\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [5 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%18 = call i32 @read(i32 %12, i8* %17, i32 5)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16, %20
%21 = phi i32 [ %23, %20 ], [ %18, %16 ]
%22 = call i32 @write(i32 1, i8* %17, i32 %21)
%23 = call i32 @read(i32 %12, i8* %17, i32 5)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %20, label %25
25: ; preds = %20, %16
%26 = tail call i32 @close(i32 %12)
ret i32 0
}