#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 */
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int *l;
};
struct TYPE_6__ {
  int format;
  int window;
  TYPE_1__ data;
  int /*<<< orphan*/ type;
};
struct TYPE_7__ {
  TYPE_2__ xclient;
};
typedef TYPE_3__ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ ClientMessage;
int /*<<< orphan*/ False;
int /*<<< orphan*/ NoEventMask;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
scalar_t__ XPending(int /*<<< orphan*/ *);
int XSendEvent(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
               int /*<<< orphan*/, TYPE_3__ *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char **argv) {
  Display *x11_display;
  XEvent message;
  int lokke;
  message.xclient.type = ClientMessage;
  message.xclient.format = 32;
  message.xclient.window = atoi(argv[1]);
  printf("Argc: %d. Window: %d\n", argc, (int)message.xclient.window);
  for (lokke = 2; lokke < argc; lokke++) {
    message.xclient.data.l[lokke - 2] = atoi(argv[lokke]);
    printf("arg %d=%d\n", lokke - 2, atoi(argv[lokke]));
  }
  x11_display = XOpenDisplay(NULL);
  XSync(x11_display, False);
  int ret = XSendEvent(x11_display, atoi(argv[1]), True, NoEventMask, &message);
  XSync(x11_display, False);
  while (XPending(x11_display)) {
  }
  XCloseDisplay(x11_display);
  printf("XSendEvent returned %d\n", ret);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0x20,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122e <main+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c4 <main+0x54>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1070 <XSync@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    0x2d78(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%r8
call   1030 <XSendEvent@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
call   1070 <XSync@plt>
mov    -0x18(%rbp),%rdi
call   1040 <XPending@plt>
cmp    $0x0,%rax
je     12b0 <main+0x140>
jmp    1298 <main+0x128>
mov    -0x18(%rbp),%rdi
call   1090 <XCloseDisplay@plt>
mov    -0x38(%rbp),%esi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movl   $0x20,(%rsp)
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,0x4(%rsp)
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,%rbx
mov    0x2e1d(%rip),%r15
mov    (%r15),%esi
mov    %rax,%rdi
call   1070 <XSync@plt>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e09(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <XSendEvent@plt>
mov    %eax,%ebp
mov    (%r15),%esi
mov    %rbx,%rdi
call   1070 <XSync@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <XPending@plt>
test   %rax,%rax
jne    1210 <main+0xa0>
mov    %rbx,%rdi
call   1090 <XCloseDisplay@plt>
lea    0xdea(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i32, i32, %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { i32* }
@ClientMessage = global i32 0
@.str = [22 x i8] c"Argc: %d. Window: %d\0A\00"
@.str.1 = [11 x i8] c"arg %d=%d\0A\00"
@False = global i32 0
@True = global i32 0
@NoEventMask = global i32 0
@.str.2 = [24 x i8] c"XSendEvent returned %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.TYPE_7__
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @ClientMessage
%11 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %11, i32 0, i32 3
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %13, i32 0, i32 0
store i32 32, i32* %14
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
%19 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %19, i32 0, i32 1
store i32 %18, i32* %20
%21 = load i32, i32* %4
%22 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %24)
store i32 2, i32* %8
br label %26
26: ; preds = %54, %2
%27 = load i32, i32* %8
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %57
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %37, i32 0, i32 2
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %38, i32 0, i32 0
%40 = load i32*, i32** %39
%41 = load i32, i32* %8
%42 = sub nsw i32 %41, 2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32 %36, i32* %44
%45 = load i32, i32* %8
%46 = sub nsw i32 %45, 2
%47 = load i8**, i8*** %5
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @atoi(i8* %51)
%53 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %52)
br label %54
54: ; preds = %30
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %26
57: ; preds = %26
%58 = call i32* @XOpenDisplay(i32* null)
store i32* %58, i32** %6
%59 = load i32*, i32** %6
%60 = load i32, i32* @False
%61 = call i32 @XSync(i32* %59, i32 %60)
%62 = load i32*, i32** %6
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
%67 = load i32, i32* @True
%68 = load i32, i32* @NoEventMask
%69 = call i32 @XSendEvent(i32* %62, i32 %66, i32 %67, i32 %68, %struct.TYPE_7__* %7)
store i32 %69, i32* %9
%70 = load i32*, i32** %6
%71 = load i32, i32* @False
%72 = call i32 @XSync(i32* %70, i32 %71)
br label %73
73: ; preds = %77, %57
%74 = load i32*, i32** %6
%75 = call i64 @XPending(i32* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %73
br label %73
78: ; preds = %73
%79 = load i32*, i32** %6
%80 = call i32 @XCloseDisplay(i32* %79)
%81 = load i32, i32* %9
%82 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %81)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i32, i32, %struct.TYPE_5__, i32 }
%struct.TYPE_5__ = type { i32* }
@ClientMessage = global i32 0
@.str = [22 x i8] c"Argc: %d. Window: %d\0A\00"
@False = global i32 0
@True = global i32 0
@NoEventMask = global i32 0
@.str.2 = [24 x i8] c"XSendEvent returned %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_7__
%4 = bitcast %struct.TYPE_7__* %3 to i8*
%5 = load i32, i32* @ClientMessage
%6 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0, i32 3
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0, i32 0
store i32 32, i32* %7
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %10)
%13 = icmp slt i32 %0, 3
%14 = tail call i32* @XOpenDisplay(i32* null)
%15 = load i32, i32* @False
%16 = tail call i32 @XSync(i32* %14, i32 %15)
%17 = load i8*, i8** %8
%18 = tail call i32 @atoi(i8* %17)
%19 = load i32, i32* @True
%20 = load i32, i32* @NoEventMask
%21 = call i32 @XSendEvent(i32* %14, i32 %18, i32 %19, i32 %20, %struct.TYPE_7__* %3)
%22 = load i32, i32* @False
%23 = call i32 @XSync(i32* %14, i32 %22)
br label %24
24: ; preds = %24, %2
%25 = call i64 @XPending(i32* %14)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %24
27: ; preds = %24
%28 = call i32 @XCloseDisplay(i32* %14)
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret i32 0
}