#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*/ CurrentTime;
int /*<<< orphan*/ RevertToPointerRoot;
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSetInputFocus(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtoul(char const *, char **, int);
int main(int argc, char **argv) {
  Display *d;
  Window w;
  const char *w_str;
  char *end;
  if (argc != 2) {
    fprintf(stderr, "Usage: focus-window WINDOWID\n");
    exit(1);
  }
  d = XOpenDisplay(NULL);
  w_str = argv[1];
  end = NULL;
  w = strtoul(w_str, &end, 16);
  if (end == w_str) {
    fprintf(stderr, "Usage: focus-window WINDOWID\n");
    exit(1);
  }
  printf("Setting input focus to 0x%lx\n", w);
  XSetInputFocus(d, w, RevertToPointerRoot, CurrentTime);
  XFlush(d);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x3f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1070 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1212 <main+0xa2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe02(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
mov    0x2da8(%rip),%rax
mov    (%rax),%ecx
call   1090 <XSetInputFocus@plt>
mov    -0x18(%rbp),%rdi
call   1060 <XFlush@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11ef <main+0x7f>
mov    %rsi,%rbp
xor    %edi,%edi
call   1040 <XOpenDisplay@plt>
mov    %rax,%r14
mov    0x8(%rbp),%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1070 <strtoul@plt>
cmp    %rbx,0x8(%rsp)
je     11ef <main+0x7f>
mov    %eax,%ebp
lea    0xe65(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    0x2e10(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rdi
mov    %ebp,%esi
call   1090 <XSetInputFocus@plt>
mov    %r14,%rdi
call   1060 <XFlush@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: focus-window WINDOWID\0A\00"
@.str.1 = [30 x i8] c"Setting input focus to 0x%lx\0A\00"
@RevertToPointerRoot = global i32 0
@CurrentTime = 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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32* @XOpenDisplay(i32* null)
store i32* %17, i32** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
store i8* null, i8** %9
%21 = load i8*, i8** %8
%22 = call i32 @strtoul(i8* %21, i8** %9, i32 16)
store i32 %22, i32* %7
%23 = load i8*, i8** %9
%24 = load i8*, i8** %8
%25 = icmp eq i8* %23, %24
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %16
%31 = load i32, i32* %7
%32 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32*, i32** %6
%34 = load i32, i32* %7
%35 = load i32, i32* @RevertToPointerRoot
%36 = load i32, i32* @CurrentTime
%37 = call i32 @XSetInputFocus(i32* %33, i32 %34, i32 %35, i32 %36)
%38 = load i32*, i32** %6
%39 = call i32 @XFlush(i32* %38)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: focus-window WINDOWID\0A\00"
@.str.1 = [30 x i8] c"Setting input focus to 0x%lx\0A\00"
@RevertToPointerRoot = global i32 0
@CurrentTime = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32* @XOpenDisplay(i32* null)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
store i8* null, i8** %3
%14 = call i32 @strtoul(i8* %13, i8** %3, i32 16)
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, %13
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%23 = load i32, i32* @RevertToPointerRoot
%24 = load i32, i32* @CurrentTime
%25 = tail call i32 @XSetInputFocus(i32* %11, i32 %14, i32 %23, i32 %24)
%26 = tail call i32 @XFlush(i32* %11)
ret i32 0
}