#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 /*<<< orphan*/ decode(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ usage(int);
int main(int argc, char *argv[]) {
  char *p;
  FILE *fd;
  while (argc > 1 && *argv[1] == '-') {
    for (p = &argv[1][1]; *p != '\0'; p++) {
      switch (*p) {
      case 'h':
        usage(0);
        break;
      default:
        fprintf(stderr, "xterm decode: unknown option -%c\n", *p);
        usage(1);
      }
    }
    argc--;
    argv++;
  }
  if (argc == 1) {
    decode(stdin);
  } else {
    while (--argc > 0) {
      if ((fd = fopen(*++argv, "r")) == NULL) {
        fprintf(stderr, "xterm_decode: can't open %s\n", *argv);
        continue;
      }
      decode(fd);
      fclose(fd);
    }
  }
}


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)
xor    %eax,%eax
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x21(%rbp)
jle    1189 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1199 <main+0x49>
jmp    1230 <main+0xe0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1216 <main+0xc6>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
sub    $0x68,%al
jne    11d8 <main+0x88>
jmp    11cc <main+0x7c>
xor    %edi,%edi
call   1050 <usage@plt>
jmp    1200 <main+0xb0>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movsbl (%rax),%edx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <usage@plt>
jmp    1205 <main+0xb5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a9 <main+0x59>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1166 <main+0x16>
cmpl   $0x1,-0x8(%rbp)
jne    124e <main+0xfe>
mov    0x2da7(%rip),%rax
mov    (%rax),%rdi
call   1060 <decode@plt>
jmp    12d1 <main+0x181>
jmp    1253 <main+0x103>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12cc <main+0x17c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xda3(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12b5 <main+0x165>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1253 <main+0x103>
mov    -0x20(%rbp),%rdi
call   1060 <decode@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1253 <main+0x103>
jmp    12d1 <main+0x181>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
cmp    $0x2,%edi
jl     11dc <main+0x8c>
lea    0x1(%r15),%r12d
lea    0x8(%rsi),%r13
mov    0x2e66(%rip),%rbp
lea    0xe87(%rip),%rbx
jmp    1199 <main+0x49>
nopl   0x0(%rax,%rax,1)
lea    -0x1(%r15),%eax
add    $0xffffffff,%r12d
add    $0x8,%r13
cmp    $0x2,%r15d
mov    %eax,%r15d
mov    (%rsp),%rsi
jle    11e2 <main+0x92>
mov    0x8(%rsi),%r14
cmpb   $0x2d,(%r14)
jne    1202 <main+0xb2>
add    $0x8,%rsi
mov    %rsi,(%rsp)
jmp    11b5 <main+0x65>
nopl   (%rax)
call   1050 <usage@plt>
add    $0x1,%r14
movsbl (%r14),%edx
xor    %edi,%edi
cmp    $0x68,%edx
je     11b0 <main+0x60>
test   %dl,%dl
je     1180 <main+0x30>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
jmp    11b0 <main+0x60>
cmp    $0x1,%r15d
jne    11f1 <main+0xa1>
mov    0x2dff(%rip),%rax
mov    (%rax),%rdi
call   1060 <decode@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe19(%rip),%r15
lea    0xe14(%rip),%r14
jmp    1241 <main+0xf1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <decode@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0xffffffff,%r12d
add    $0x8,%r13
cmp    $0x2,%r12d
jbe    11f1 <main+0xa1>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    1220 <main+0xd0>
mov    0x0(%rbp),%edi
mov    0x0(%r13),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1233 <main+0xe3>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"xterm decode: unknown option -%c\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"xterm_decode: can't open %s\0A\00"
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
br label %8
8: ; preds = %47, %2
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 45
br label %18
18: ; preds = %11, %8
%19 = phi i1 [ false, %8 ], [ %17, %11 ]
br i1 %19, label %20, label %52
20: ; preds = %18
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %6
br label %25
25: ; preds = %44, %20
%26 = load i8*, i8** %6
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
switch i32 %33, label %36 [
i32 104, label %34
]
34: ; preds = %30
%35 = call i32 @usage(i32 0)
br label %43
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %6
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = call i32 @usage(i32 1)
br label %43
43: ; preds = %36, %34
br label %44
44: ; preds = %43
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %6
br label %25
47: ; preds = %25
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
store i32 %49, i32* %4
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %5
br label %8
52: ; preds = %18
%53 = load i32, i32* %4
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32*, i32** @stdin
%57 = call i32 @decode(i32* %56)
br label %80
58: ; preds = %52
br label %59
59: ; preds = %74, %69, %58
%60 = load i32, i32* %4
%61 = add nsw i32 %60, -1
store i32 %61, i32* %4
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %79
63: ; preds = %59
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i32 1
store i8** %65, i8*** %5
%66 = load i8*, i8** %65
%67 = call i32* @fopen(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %67, i32** %7
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %74
69: ; preds = %63
%70 = load i32, i32* @stderr
%71 = load i8**, i8*** %5
%72 = load i8*, i8** %71
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %72)
br label %59
74: ; preds = %63
%75 = load i32*, i32** %7
%76 = call i32 @decode(i32* %75)
%77 = load i32*, i32** %7
%78 = call i32 @fclose(i32* %77)
br label %59
79: ; preds = %59
br label %80
80: ; preds = %79, %55
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"xterm decode: unknown option -%c\0A\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"xterm_decode: can't open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %25
4: ; preds = %2, %22
%5 = phi i32 [ %23, %22 ], [ %0, %2 ]
%6 = phi i8** [ %7, %22 ], [ %1, %2 ]
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 45
br i1 %10, label %11, label %30
11: ; preds = %4, %19
%12 = phi i8* [ %13, %19 ], [ %8, %4 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 0, label %22
i8 104, label %19
]
15: ; preds = %11
%16 = sext i8 %14 to i32
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %19
19: ; preds = %11, %15
%20 = phi i32 [ 1, %15 ], [ 0, %11 ]
%21 = tail call i32 @usage(i32 %20)
br label %11
22: ; preds = %11
%23 = add nsw i32 %5, -1
%24 = icmp sgt i32 %5, 2
br i1 %24, label %4, label %27
25: ; preds = %2
%26 = icmp eq i32 %0, 1
br i1 %26, label %27, label %47
27: ; preds = %22, %25
%28 = load i32*, i32** @stdin
%29 = tail call i32 @decode(i32* %28)
br label %47
30: ; preds = %4, %42
%31 = phi i32 [ %33, %42 ], [ %5, %4 ]
%32 = phi i8** [ %34, %42 ], [ %6, %4 ]
%33 = add nsw i32 %31, -1
%34 = getelementptr inbounds i8*, i8** %32, i64 1
%35 = load i8*, i8** %34
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %34
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %38, %44
%43 = icmp ugt i32 %31, 2
br i1 %43, label %30, label %47
44: ; preds = %30
%45 = tail call i32 @decode(i32* %36)
%46 = tail call i32 @fclose(i32* %36)
br label %42
47: ; preds = %42, %25, %27
ret i32 0
}