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

/* Variables and functions */
scalar_t__ None;
int /*<<< orphan*/ RootWindow(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XCopyArea(int /*<<< orphan*/ *, scalar_t__, scalar_t__,
                             int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/, unsigned int, unsigned int,
                             int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XCreateGC(int /*<<< orphan*/ *, scalar_t__,
                             int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ XCreatePixmap(int /*<<< orphan*/ *, int /*<<< orphan*/, unsigned int,
                         unsigned int, unsigned int);
int /*<<< orphan*/ XFreeGC(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XGetGeometry(int /*<<< orphan*/ *, scalar_t__,
                                int /*<<< orphan*/ *, int *, int *,
                                unsigned int *, unsigned int *, unsigned int *,
                                unsigned int *);
Pixmap ClonePixmap(Display *xDpy, int screenId, Pixmap targetPixmap) {
  Pixmap newPixmap = None;
  GC gc;
  unsigned int width, height, depth;
  Window parent;
  int x, y;
  unsigned int borderWidth;
  XGetGeometry(xDpy, targetPixmap, &parent, &x, &y, &width, &height,
               &borderWidth, &depth);
  newPixmap =
      XCreatePixmap(xDpy, RootWindow(xDpy, screenId), width, height, depth);
  if (newPixmap == None) {
    return None;
  }
  gc = XCreateGC(xDpy, newPixmap, 0, NULL);
  XCopyArea(xDpy, targetPixmap, newPixmap, gc, 0, 0, width, height, 0, 0);
  XFreeGC(xDpy, gc);
  return newPixmap;
}


x86 assembly (clang, -O0):
<ClonePixmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%r11
lea    -0x48(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1050 <XGetGeometry@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <RootWindow@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
call   1080 <XCreatePixmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
jne    120c <ClonePixmap+0xac>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    126f <ClonePixmap+0x10f>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <XCreateGC@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r10d
mov    -0x34(%rbp),%eax
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1030 <XCopyArea@plt>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <XFreeGC@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ClonePixmap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%r15
sub    $0x8,%rsp
lea    0x1c(%rsp),%rax
lea    0x20(%rsp),%rbp
lea    0x14(%rsp),%r10
lea    0x2c(%rsp),%rdx
lea    0x28(%rsp),%rcx
lea    0x24(%rsp),%r8
lea    0x18(%rsp),%r9
mov    %r14,%rsi
push   %rax
push   %rbp
push   %r10
call   1050 <XGetGeometry@plt>
add    $0x20,%rsp
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <RootWindow@plt>
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    %r15,%rdi
mov    %eax,%esi
call   1080 <XCreatePixmap@plt>
mov    %rax,%rbx
mov    0x2e14(%rip),%rax
cmp    (%rax),%rbx
je     121e <ClonePixmap+0xbe>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <XCreateGC@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%r10d
mov    0xc(%rsp),%eax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
push   %rax
push   %r10
call   1030 <XCopyArea@plt>
add    $0x20,%rsp
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <XFreeGC@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@None = global i64 0
define i64 @ClonePixmap(i32* %0, i32 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%17 = load i64, i64* @None
store i64 %17, i64* %8
%18 = load i32*, i32** %5
%19 = load i64, i64* %7
%20 = call i32 @XGetGeometry(i32* %18, i64 %19, i32* %13, i32* %14, i32* %15, i32* %10, i32* %11, i32* %16, i32* %12)
%21 = load i32*, i32** %5
%22 = load i32*, i32** %5
%23 = load i32, i32* %6
%24 = call i32 @RootWindow(i32* %22, i32 %23)
%25 = load i32, i32* %10
%26 = load i32, i32* %11
%27 = load i32, i32* %12
%28 = call i64 @XCreatePixmap(i32* %21, i32 %24, i32 %25, i32 %26, i32 %27)
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = load i64, i64* @None
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %3
%33 = load i64, i64* @None
store i64 %33, i64* %4
br label %49
34: ; preds = %3
%35 = load i32*, i32** %5
%36 = load i64, i64* %8
%37 = call i32 @XCreateGC(i32* %35, i64 %36, i32 0, i32* null)
store i32 %37, i32* %9
%38 = load i32*, i32** %5
%39 = load i64, i64* %7
%40 = load i64, i64* %8
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = call i32 @XCopyArea(i32* %38, i64 %39, i64 %40, i32 %41, i32 0, i32 0, i32 %42, i32 %43, i32 0, i32 0)
%45 = load i32*, i32** %5
%46 = load i32, i32* %9
%47 = call i32 @XFreeGC(i32* %45, i32 %46)
%48 = load i64, i64* %8
store i64 %48, i64* %4
br label %49
49: ; preds = %34, %32
%50 = load i64, i64* %4
ret i64 %50
}

LLVM IR (-O2):
@None = global i64 0
define i64 @ClonePixmap(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast i32* %6 to i8*
%14 = bitcast i32* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast i32* %9 to i8*
%17 = bitcast i32* %10 to i8*
%18 = call i32 @XGetGeometry(i32* %0, i64 %2, i32* %7, i32* %8, i32* %9, i32* %4, i32* %5, i32* %10, i32* %6)
%19 = call i32 @RootWindow(i32* %0, i32 %1)
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i64 @XCreatePixmap(i32* %0, i32 %19, i32 %20, i32 %21, i32 %22)
%24 = load i64, i64* @None
%25 = icmp eq i64 %23, %24
br i1 %25, label %32, label %26
26: ; preds = %3
%27 = call i32 @XCreateGC(i32* %0, i64 %23, i32 0, i32* null)
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = call i32 @XCopyArea(i32* %0, i64 %2, i64 %23, i32 %27, i32 0, i32 0, i32 %28, i32 %29, i32 0, i32 0)
%31 = call i32 @XFreeGC(i32* %0, i32 %27)
br label %32
32: ; preds = %3, %26
ret i64 %23
}