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

/* Variables and functions */
int /*<<< orphan*/ False;
int /*<<< orphan*/ PropModeReplace;
int /*<<< orphan*/ XA_CARDINAL;
int /*<<< orphan*/ XChangeProperty(int /*<<< orphan*/ *, int, scalar_t__,
                                   int /*<<< orphan*/, int, int /*<<< orphan*/,
                                   void *, int);
scalar_t__ XInternAtom(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int getpid();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
void __e_hack_set_properties(Display *display, Window window) {
  static Atom net_wm_pid = 0;
  if (!net_wm_pid)
    net_wm_pid = XInternAtom(display, "_NET_WM_PID", False);
  {
    pid_t pid;
    char buf[4096];
    pid = getpid();
    snprintf(buf, sizeof(buf), "%i", pid);
    XChangeProperty(display, window, net_wm_pid, XA_CARDINAL, 32,
                    PropModeReplace, (void *)&pid, 1);
    fprintf(stderr, "-- trapped window creation: window=%d, pid=%d\n", window,
            pid);
  }
}


x86 assembly (clang, -O0):
<__e_hack_set_properties>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,0x2ee6(%rip)
jne    1190 <__e_hack_set_properties+0x40>
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0xe7c(%rip),%rsi
call   1060 <XInternAtom@plt>
mov    %rax,0x2ec0(%rip)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x1000,%esi
lea    0xe5c(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e8d(%rip),%rdx
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
mov    0x2df5(%rip),%rax
mov    (%rax),%r9d
lea    -0x10(%rbp),%rax
mov    $0x20,%r8d
mov    %rax,(%rsp)
movl   $0x1,0x8(%rsp)
call   1070 <XChangeProperty@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__e_hack_set_properties>:
push   %rbp
push   %rbx
sub    $0x1018,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
cmpq   $0x0,0x2eea(%rip)
jne    1187 <__e_hack_set_properties+0x37>
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1060 <XInternAtom@plt>
mov    %rax,0x2ec9(%rip)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0xc(%rsp)
lea    0xe73(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    0x2e9f(%rip),%rdx
mov    0x2e18(%rip),%rax
mov    (%rax),%ecx
mov    0x2e07(%rip),%rax
mov    (%rax),%r9d
lea    0xc(%rsp),%rax
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x20,%r8d
push   $0x1
push   %rax
call   1070 <XChangeProperty@plt>
add    $0x10,%rsp
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%ecx
lea    0xe1b(%rip),%rsi
mov    %ebp,%edx
call   1050 <fprintf@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__e_hack_set_properties.net_wm_pid = internal global i64 0
@.str = [12 x i8] c"_NET_WM_PID\00"
@False = global i32 0
@.str.1 = [3 x i8] c"%i\00"
@XA_CARDINAL = global i32 0
@PropModeReplace = global i32 0
@stderr = global i32 0
@.str.2 = [47 x i8] c"-- trapped window creation: window=%d, pid=%d\0A\00"
define void @__e_hack_set_properties(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i64, i64* @__e_hack_set_properties.net_wm_pid
%8 = icmp ne i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32*, i32** %3
%11 = load i32, i32* @False
%12 = call i64 @XInternAtom(i32* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
store i64 %12, i64* @__e_hack_set_properties.net_wm_pid
br label %13
13: ; preds = %9, %2
%14 = call i32 (...) @getpid()
store i32 %14, i32* %5
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %5
%17 = call i32 @snprintf(i8* %15, i32 4096, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %3
%19 = load i32, i32* %4
%20 = load i64, i64* @__e_hack_set_properties.net_wm_pid
%21 = load i32, i32* @XA_CARDINAL
%22 = load i32, i32* @PropModeReplace
%23 = bitcast i32* %5 to i8*
%24 = call i32 @XChangeProperty(i32* %18, i32 %19, i64 %20, i32 %21, i32 32, i32 %22, i8* %23, i32 1)
%25 = load i32, i32* @stderr
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %27)
ret void
}

LLVM IR (-O2):
@__e_hack_set_properties.net_wm_pid = internal unnamed_addr global i64 0
@.str = [12 x i8] c"_NET_WM_PID\00"
@False = global i32 0
@.str.1 = [3 x i8] c"%i\00"
@XA_CARDINAL = global i32 0
@PropModeReplace = global i32 0
@stderr = global i32 0
@.str.2 = [47 x i8] c"-- trapped window creation: window=%d, pid=%d\0A\00"
define void @__e_hack_set_properties(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = load i64, i64* @__e_hack_set_properties.net_wm_pid
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @False
%9 = tail call i64 @XInternAtom(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i64 %9, i64* @__e_hack_set_properties.net_wm_pid
br label %10
10: ; preds = %7, %2
%11 = bitcast i32* %3 to i8*
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%13 = tail call i32 (...) @getpid()
store i32 %13, i32* %3
%14 = call i32 @snprintf(i8* %12, i32 4096, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i64, i64* @__e_hack_set_properties.net_wm_pid
%16 = load i32, i32* @XA_CARDINAL
%17 = load i32, i32* @PropModeReplace
%18 = call i32 @XChangeProperty(i32* %0, i32 %1, i64 %15, i32 %16, i32 32, i32 %17, i8* %11, i32 1)
%19 = load i32, i32* @stderr
%20 = load i32, i32* %3
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %1, i32 %20)
ret void
}