#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*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int listMapped(int /*<<< orphan*/ *, char *);
int raiseWindow(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char **);
int main(int argc, char **argv) {
  int ret = 2;
  if (argc < 2 || argc > 3) {
    usage(argv);
    return 2;
  }
  Display *display = XOpenDisplay(NULL);
  if (!display) {
    fputs("Unable to open display\n", stderr);
    return 1;
  }
  switch (argv[1][0]) {
  case 'l':
    if (argc > 3) {
      usage(argv);
      break;
    }
    ret = listMapped(display, argc >= 3 ? argv[2] : "");
    break;
  case 'r':
    if (argc != 3) {
      usage(argv);
      break;
    }
    ret = raiseWindow(display, (Window)strtol(argv[2], NULL, 0));
    break;
  default:
    usage(argv);
    break;
  }
  XCloseDisplay(display);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11a1 <main+0x31>
cmpl   $0x3,-0x8(%rbp)
jle    11b6 <main+0x46>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
movl   $0x2,-0x4(%rbp)
jmp    12da <main+0x16a>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <main+0x7f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
call   1030 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12da <main+0x16a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6c,%eax
je     121c <main+0xac>
jmp    120b <main+0x9b>
mov    -0x24(%rbp),%eax
sub    $0x72,%eax
je     127c <main+0x10c>
jmp    12c2 <main+0x152>
cmpl   $0x3,-0x8(%rbp)
jle    1234 <main+0xc4>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
jmp    12cb <main+0x15b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1257 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1267 <main+0xf7>
lea    0xdb9(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1267 <main+0xf7>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <listMapped@plt>
mov    %eax,-0x14(%rbp)
jmp    12cb <main+0x15b>
cmpl   $0x3,-0x8(%rbp)
je     1294 <main+0x124>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
jmp    12cb <main+0x15b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
call   1090 <raiseWindow@plt>
mov    %eax,-0x14(%rbp)
jmp    12cb <main+0x15b>
mov    -0x10(%rbp),%rdi
call   1060 <usage@plt>
mov    -0x20(%rbp),%rdi
call   1080 <XCloseDisplay@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     1194 <main+0x24>
mov    %r15,%rdi
call   1060 <usage@plt>
mov    $0x2,%ebx
jmp    1221 <main+0xb1>
xor    %edi,%edi
call   1040 <XOpenDisplay@plt>
test   %rax,%rax
je     11bf <main+0x4f>
mov    %rax,%r14
mov    0x8(%r15),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
je     11db <main+0x6b>
cmp    $0x6c,%eax
jne    11f9 <main+0x89>
cmp    $0x3,%ebx
jb     1208 <main+0x98>
mov    0x10(%r15),%rsi
jmp    120f <main+0x9f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    0xe31(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%ebx
jmp    1221 <main+0xb1>
cmp    $0x3,%ebx
jne    11f9 <main+0x89>
mov    0x10(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1090 <raiseWindow@plt>
jmp    1217 <main+0xa7>
mov    %r15,%rdi
call   1060 <usage@plt>
mov    $0x2,%ebx
jmp    1219 <main+0xa9>
lea    0xe08(%rip),%rsi
mov    %r14,%rdi
call   1070 <listMapped@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1080 <XCloseDisplay@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Unable to open display\0A\00"
@stderr = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %10, %2
%14 = load i8**, i8*** %5
%15 = call i32 @usage(i8** %14)
store i32 2, i32* %3
br label %68
16: ; preds = %10
%17 = call i32* @XOpenDisplay(i32* null)
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 1, i32* %3
br label %68
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %61 [
i32 108, label %30
i32 114, label %48
]
30: ; preds = %23
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 3
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = call i32 @usage(i8** %34)
br label %64
36: ; preds = %30
%37 = load i32*, i32** %7
%38 = load i32, i32* %4
%39 = icmp sge i32 %38, 3
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
br label %45
44: ; preds = %36
br label %45
45: ; preds = %44, %40
%46 = phi i8* [ %43, %40 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %44 ]
%47 = call i32 @listMapped(i32* %37, i8* %46)
store i32 %47, i32* %6
br label %64
48: ; preds = %23
%49 = load i32, i32* %4
%50 = icmp ne i32 %49, 3
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8**, i8*** %5
%53 = call i32 @usage(i8** %52)
br label %64
54: ; preds = %48
%55 = load i32*, i32** %7
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @strtol(i8* %58, i32* null, i32 0)
%60 = call i32 @raiseWindow(i32* %55, i32 %59)
store i32 %60, i32* %6
br label %64
61: ; preds = %23
%62 = load i8**, i8*** %5
%63 = call i32 @usage(i8** %62)
br label %64
64: ; preds = %61, %54, %51, %45, %33
%65 = load i32*, i32** %7
%66 = call i32 @XCloseDisplay(i32* %65)
%67 = load i32, i32* %6
store i32 %67, i32* %3
br label %68
68: ; preds = %64, %20, %13
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [24 x i8] c"Unable to open display\0A\00"
@stderr = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @usage(i8** %1)
br label %40
7: ; preds = %2
%8 = tail call i32* @XOpenDisplay(i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %40
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %35 [
i32 108, label %18
i32 114, label %26
]
18: ; preds = %13
%19 = icmp ugt i32 %0, 2
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
br label %23
23: ; preds = %18, %20
%24 = phi i8* [ %22, %20 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %18 ]
%25 = tail call i32 @listMapped(i32* %8, i8* %24)
br label %37
26: ; preds = %13
%27 = icmp eq i32 %0, 3
br i1 %27, label %30, label %28
28: ; preds = %26
%29 = tail call i32 @usage(i8** %1)
br label %37
30: ; preds = %26
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = tail call i32 @strtol(i8* nocapture %32, i32* null, i32 0)
%34 = tail call i32 @raiseWindow(i32* %8, i32 %33)
br label %37
35: ; preds = %13
%36 = tail call i32 @usage(i8** %1)
br label %37
37: ; preds = %35, %30, %28, %23
%38 = phi i32 [ 2, %35 ], [ 2, %28 ], [ %34, %30 ], [ %25, %23 ]
%39 = tail call i32 @XCloseDisplay(i32* %8)
br label %40
40: ; preds = %10, %37, %5
%41 = phi i32 [ 2, %5 ], [ %38, %37 ], [ 1, %10 ]
ret i32 %41
}