#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*/ display_file(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  if (argc != 2) {
    if (argc > 2)
      write(2, "Too many arguments.\n", 20);
    else
      write(2, "File name missing.\n", 19);
    return (1);
  }
  fd = open(argv[1], O_RDONLY);
  display_file(fd);
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a7 <main+0x67>
cmpl   $0x2,-0x8(%rbp)
jle    1185 <main+0x45>
mov    $0x2,%edi
lea    0xe8a(%rip),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
jmp    119b <main+0x5b>
mov    $0x2,%edi
lea    0xe84(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <display_file@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    116c <main+0x2c>
mov    0x8(%rsi),%rdi
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <display_file@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
jle    1181 <main+0x41>
lea    0xe8b(%rip),%rsi
mov    $0x2,%edi
mov    $0x14,%edx
jmp    1192 <main+0x52>
lea    0xe8d(%rip),%rsi
mov    $0x2,%edi
mov    $0x13,%edx
call   1030 <write@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Too many arguments.\0A\00"
@.str.1 = [20 x i8] c"File name missing.\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @write(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 20)
br label %16
14: ; preds = %9
%15 = call i32 @write(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 19)
br label %16
16: ; preds = %14, %12
store i32 1, i32* %3
br label %27
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @display_file(i32 %23)
%25 = load i32, i32* %6
%26 = call i32 @close(i32 %25)
store i32 0, i32* %3
br label %27
27: ; preds = %17, %16
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [21 x i8] c"Too many arguments.\0A\00"
@.str.1 = [20 x i8] c"File name missing.\0A\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 20)
br label %17
8: ; preds = %4
%9 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 19)
br label %17
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = tail call i32 @display_file(i32 %14)
%16 = tail call i32 @close(i32 %14)
br label %17
17: ; preds = %6, %8, %10
%18 = phi i32 [ 0, %10 ], [ 1, %8 ], [ 1, %6 ]
ret i32 %18
}