#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int decode(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *rindex(char *, char);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage(int /*<<< orphan*/, char const *);
int main(int argc, char **argv) {
  const char *name;
  FILE *input;
  name = rindex(argv[0], '/');
  if (name == NULL)
    name = argv[0];
  else
    name++;
  if (argc > 2) {
    fprintf(stderr, "Invalid number of arguments\n");
    usage(stderr, name);
    exit(1);
  } else if (argc > 1) {
    input = fopen(argv[1], "r");
    if (input == NULL) {
      fprintf(stderr, "Failed opening %s: %s\n", argv[1], strerror(errno));
    }
  } else {
    input = stdin;
  }
  setlinebuf(stdout);
  return decode(input);
}


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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2f,%esi
call   1080 <rindex@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <main+0x52>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    120f <main+0x8f>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jle    127f <main+0xff>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    127a <main+0xfa>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    128d <main+0x10d>
mov    0x2d62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1292 <main+0x112>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1030 <setlinebuf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <decode@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    (%rsi),%rdi
mov    $0x2f,%esi
call   1080 <rindex@plt>
test   %rax,%rax
je     1221 <main+0xa1>
mov    %rax,%rbx
add    $0x1,%rbx
cmp    $0x3,%ebp
jge    1229 <main+0xa9>
cmp    $0x2,%ebp
jne    11fd <main+0x7d>
mov    0x8(%r14),%rdi
lea    0xe62(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1207 <main+0x87>
mov    0x2e09(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%r14),%r14
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe35(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1207 <main+0x87>
mov    0x2de4(%rip),%rax
mov    (%rax),%rbx
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1030 <setlinebuf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <decode@plt>
mov    (%r14),%rbx
cmp    $0x3,%ebp
jl     11ab <main+0x2b>
mov    0x2da8(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
call   1050 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Invalid number of arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Failed opening %s: %s\0A\00"
@errno = global i32 0
@stdin = global i32* null
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i8* @rindex(i8* %10, i8 signext 47)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
store i8* %17, i8** %6
br label %21
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 2
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = call i32 @usage(i32 %27, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 1
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %49
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %47)
br label %49
49: ; preds = %41, %34
br label %52
50: ; preds = %31
%51 = load i32*, i32** @stdin
store i32* %51, i32** %7
br label %52
52: ; preds = %50, %49
br label %53
53: ; preds = %52
%54 = load i32, i32* @stdout
%55 = call i32 @setlinebuf(i32 %54)
%56 = load i32*, i32** %7
%57 = call i32 @decode(i32* %56)
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Invalid number of arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Failed opening %s: %s\0A\00"
@errno = global i32 0
@stdin = global i32* null
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i8* @rindex(i8* %3, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i8*, i8** %1
br label %10
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %4, i64 1
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %7, %6 ], [ %9, %8 ]
%12 = icmp sgt i32 %0, 2
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = tail call i32 @usage(i32 %16, i8* %11)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = icmp eq i32 %0, 2
br i1 %20, label %21, label %32
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %22
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %30)
br label %34
32: ; preds = %19
%33 = load i32*, i32** @stdin
br label %34
34: ; preds = %32, %26, %21
%35 = phi i32* [ null, %26 ], [ %24, %21 ], [ %33, %32 ]
%36 = load i32, i32* @stdout
%37 = tail call i32 @setlinebuf(i32 %36)
%38 = tail call i32 @decode(i32* %35)
ret i32 %38
}