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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
void *None;
int /*<<< orphan*/ XBell(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XkbBell(int /*<<< orphan*/ *, void *, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
void *strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i, pct = 100;
  char *arg;
  Window w = None;
  char xkb_bell = 0;
  for (i = 1; i < argc; i++) {
    arg = argv[i];
    if (!strcmp(arg, "-window")) {
      if (i + 1 >= argc)
        goto argfail;
      w = strtol(argv[++i], NULL, 0);
      printf("w = %ld (0x%08lx)\n", w, w);
    } else if (!strcmp(arg, "-xkb")) {
      xkb_bell = 1;
    } else if (!strcmp(arg, "-x")) {
      xkb_bell = 0;
    } else if (!strcmp(arg, "-pct")) {
      if (i + 1 >= argc)
        goto argfail;
      pct = strtol(argv[++i], NULL, 0);
      printf("pct = %d\n", pct);
    }
  }
  Display *disp = XOpenDisplay(NULL);
  if (xkb_bell)
    XkbBell(disp, w, pct, (Atom)NULL);
  else
    XBell(disp, pct);
  return EXIT_SUCCESS;
argfail:
  fprintf(stderr, "Failed to parse arguments\n");
  fflush(stderr);
  return EXIT_FAILURE;
}


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   $0x64,-0x18(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1305 <main+0x185>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    123f <main+0xbf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     11ff <main+0x7f>
jmp    1350 <main+0x1d0>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f2 <main+0x172>
mov    -0x20(%rbp),%rdi
lea    0xdd1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1261 <main+0xe1>
movb   $0x1,-0x29(%rbp)
jmp    12ed <main+0x16d>
mov    -0x20(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1283 <main+0x103>
movb   $0x0,-0x29(%rbp)
jmp    12e8 <main+0x168>
mov    -0x20(%rbp),%rdi
lea    0xd95(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12e3 <main+0x163>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     12b0 <main+0x130>
jmp    1350 <main+0x1d0>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12e8 <main+0x168>
jmp    12ed <main+0x16d>
jmp    12f2 <main+0x172>
jmp    12f7 <main+0x177>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <main+0x36>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x38(%rbp)
cmpb   $0x0,-0x29(%rbp)
je     1333 <main+0x1b3>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1040 <XkbBell@plt>
jmp    133f <main+0x1bf>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <XBell@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    137f <main+0x1ff>
mov    0x2c81(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     12b2 <main+0x132>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e45(%rip),%rax
mov    (%rax),%r15
mov    $0x64,%eax
mov    %rax,0x10(%rsp)
mov    $0x1,%r13d
lea    0xe43(%rip),%r12
movl   $0x0,0xc(%rsp)
jmp    11e3 <main+0x63>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%al
mov    %eax,0xc(%rsp)
add    $0x1,%r13d
cmp    %ebp,%r13d
jge    12c0 <main+0x140>
movslq %r13d,%rax
mov    (%rbx,%rax,8),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1270 <main+0xf0>
mov    %r14,%rdi
lea    0xe18(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11d0 <main+0x50>
mov    %r14,%rdi
lea    0xe0a(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12a5 <main+0x125>
mov    %r14,%rdi
lea    0xdf6(%rip),%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11d6 <main+0x56>
add    $0x1,%r13d
cmp    %ebp,%r13d
jge    12e2 <main+0x162>
movslq %r13d,%rax
mov    (%rbx,%rax,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
lea    0xdce(%rip),%rdi
mov    %rax,0x10(%rsp)
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d6 <main+0x56>
nopl   (%rax)
add    $0x1,%r13d
cmp    %ebp,%r13d
jge    12e2 <main+0x162>
movslq %r13d,%rax
mov    (%rbx,%rax,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %rax,%r15
lea    0xd75(%rip),%rdi
mov    %r15d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d6 <main+0x56>
movl   $0x0,0xc(%rsp)
jmp    11d6 <main+0x56>
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
mov    $0x64,%esi
jmp    130c <main+0x18c>
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
cmpb   $0x0,0xc(%rsp)
je     1307 <main+0x187>
mov    %rax,%rdi
mov    %r15,%rsi
mov    0x10(%rsp),%rdx
xor    %ecx,%ecx
call   1040 <XkbBell@plt>
jmp    1314 <main+0x194>
mov    0x2cef(%rip),%rbx
mov    (%rbx),%edi
lea    0xd40(%rip),%rsi
call   1080 <fprintf@plt>
mov    (%rbx),%edi
call   10a0 <fflush@plt>
mov    0x2ccb(%rip),%rax
jmp    131b <main+0x19b>
mov    0x10(%rsp),%rsi
mov    %rax,%rdi
call   1030 <XBell@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@None = global i8* null
@.str = [8 x i8] c"-window\00"
@.str.1 = [19 x i8] c"w = %ld (0x%08lx)\0A\00"
@.str.2 = [5 x i8] c"-xkb\00"
@.str.3 = [3 x i8] c"-x\00"
@.str.4 = [5 x i8] c"-pct\00"
@.str.5 = [10 x i8] c"pct = %d\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.6 = [27 x i8] c"Failed to parse arguments\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 100, i32* %7
%12 = load i8*, i8** @None
store i8* %12, i8** %9
store i8 0, i8* %10
store i32 1, i32* %6
br label %13
13: ; preds = %79, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %82
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %44, label %26
26: ; preds = %17
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %4
%30 = icmp sge i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %26
br label %97
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i8* @strtol(i8* %38, i32* null, i32 0)
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = ptrtoint i8* %40 to i32
%42 = load i8*, i8** %9
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %41, i8* %42)
br label %78
44: ; preds = %17
%45 = load i8*, i8** %8
%46 = call i32 @strcmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
store i8 1, i8* %10
br label %77
49: ; preds = %44
%50 = load i8*, i8** %8
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %49
store i8 0, i8* %10
br label %76
54: ; preds = %49
%55 = load i8*, i8** %8
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %75, label %58
58: ; preds = %54
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = load i32, i32* %4
%62 = icmp sge i32 %60, %61
br i1 %62, label %63, label %64
63: ; preds = %58
br label %97
64: ; preds = %58
%65 = load i8**, i8*** %5
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %65, i64 %68
%70 = load i8*, i8** %69
%71 = call i8* @strtol(i8* %70, i32* null, i32 0)
%72 = ptrtoint i8* %71 to i32
store i32 %72, i32* %7
%73 = load i32, i32* %7
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %64, %54
br label %76
76: ; preds = %75, %53
br label %77
77: ; preds = %76, %48
br label %78
78: ; preds = %77, %32
br label %79
79: ; preds = %78
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
store i32 %81, i32* %6
br label %13
82: ; preds = %13
%83 = call i32* @XOpenDisplay(i32* null)
store i32* %83, i32** %11
%84 = load i8, i8* %10
%85 = icmp ne i8 %84, 0
br i1 %85, label %86, label %91
86: ; preds = %82
%87 = load i32*, i32** %11
%88 = load i8*, i8** %9
%89 = load i32, i32* %7
%90 = call i32 @XkbBell(i32* %87, i8* %88, i32 %89, i32 0)
br label %95
91: ; preds = %82
%92 = load i32*, i32** %11
%93 = load i32, i32* %7
%94 = call i32 @XBell(i32* %92, i32 %93)
br label %95
95: ; preds = %91, %86
%96 = load i32, i32* @EXIT_SUCCESS
store i32 %96, i32* %3
br label %103
97: ; preds = %63, %31
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%100 = load i32, i32* @stderr
%101 = call i32 @fflush(i32 %100)
%102 = load i32, i32* @EXIT_FAILURE
store i32 %102, i32* %3
br label %103
103: ; preds = %97, %95
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@None = global i8* null
@.str = [8 x i8] c"-window\00"
@.str.1 = [19 x i8] c"w = %ld (0x%08lx)\0A\00"
@.str.2 = [5 x i8] c"-xkb\00"
@.str.3 = [3 x i8] c"-x\00"
@.str.4 = [5 x i8] c"-pct\00"
@.str.5 = [10 x i8] c"pct = %d\0A\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.6 = [27 x i8] c"Failed to parse arguments\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i8*, i8** @None
br label %8
6: ; preds = %2
%7 = tail call i32* @XOpenDisplay(i32* null)
br label %61
8: ; preds = %4, %49
%9 = phi i8 [ %53, %49 ], [ 0, %4 ]
%10 = phi i8* [ %52, %49 ], [ %5, %4 ]
%11 = phi i32 [ %54, %49 ], [ 1, %4 ]
%12 = phi i32 [ %50, %49 ], [ 100, %4 ]
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %8
%19 = add nsw i32 %11, 1
%20 = icmp slt i32 %19, %0
br i1 %20, label %21, label %65
21: ; preds = %18
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i8* @strtol(i8* nocapture %24, i32* null, i32 0)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i32
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %25)
br label %49
29: ; preds = %8
%30 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %49, label %32
32: ; preds = %29
%33 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
br i1 %34, label %49, label %35
35: ; preds = %32
%36 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = add nsw i32 %11, 1
%40 = icmp slt i32 %39, %0
br i1 %40, label %41, label %65
41: ; preds = %38
%42 = sext i32 %39 to i64
%43 = getelementptr inbounds i8*, i8** %1, i64 %42
%44 = load i8*, i8** %43
%45 = tail call i8* @strtol(i8* nocapture %44, i32* null, i32 0)
%46 = ptrtoint i8* %45 to i64
%47 = trunc i64 %46 to i32
%48 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %32, %29, %21, %41, %35
%50 = phi i32 [ %12, %35 ], [ %47, %41 ], [ %12, %21 ], [ %12, %29 ], [ %12, %32 ]
%51 = phi i32 [ %11, %35 ], [ %39, %41 ], [ %19, %21 ], [ %11, %29 ], [ %11, %32 ]
%52 = phi i8* [ %10, %35 ], [ %10, %41 ], [ %25, %21 ], [ %10, %29 ], [ %10, %32 ]
%53 = phi i8 [ %9, %35 ], [ %9, %41 ], [ %9, %21 ], [ 1, %29 ], [ 0, %32 ]
%54 = add nsw i32 %51, 1
%55 = icmp slt i32 %54, %0
br i1 %55, label %8, label %56
56: ; preds = %49
%57 = tail call i32* @XOpenDisplay(i32* null)
%58 = icmp eq i8 %53, 0
br i1 %58, label %61, label %59
59: ; preds = %56
%60 = tail call i32 @XkbBell(i32* %57, i8* %52, i32 %50, i32 0)
br label %70
61: ; preds = %6, %56
%62 = phi i32* [ %7, %6 ], [ %57, %56 ]
%63 = phi i32 [ 100, %6 ], [ %50, %56 ]
%64 = tail call i32 @XBell(i32* %62, i32 %63)
br label %70
65: ; preds = %38, %18
%66 = load i32, i32* @stderr
%67 = tail call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%68 = load i32, i32* @stderr
%69 = tail call i32 @fflush(i32 %68)
br label %70
70: ; preds = %59, %61, %65
%71 = phi i32* [ @EXIT_FAILURE, %65 ], [ @EXIT_SUCCESS, %61 ], [ @EXIT_SUCCESS, %59 ]
%72 = load i32, i32* %71
ret i32 %72
}