#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  void *test_type;
  void *wait_value;
  void *value_type;
  void *counter;
};
struct TYPE_5__ {
  TYPE_1__ trigger;
};
typedef TYPE_2__ XSyncWaitCondition;
typedef void *XSyncValue;
typedef void *XSyncCounter;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
void *XSyncAbsolute;
int /*<<< orphan*/ XSyncAwait(int /*<<< orphan*/ *, TYPE_2__ *, int);
void *XSyncCreateCounter(int /*<<< orphan*/ *, void *);
int /*<<< orphan*/ XSyncInitialize(int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ XSyncIntToValue(void **, int);
void *XSyncPositiveTransition;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ printf(char *);
int main(void) {
  {
    Display *display = XOpenDisplay(NULL);
    if (!display) {
      abort();
    }
    int major = 3;
    int minor = 1;
    XSyncInitialize(display, &major, &minor);
    XSyncValue value;
    XSyncIntToValue(&value, 0);
    XSyncCounter counter = XSyncCreateCounter(display, value);
    static XSyncWaitCondition wait_list[1];
    XSyncIntToValue(&value, 123);
    wait_list[0].trigger.counter = counter;
    wait_list[0].trigger.value_type = XSyncAbsolute;
    wait_list[0].trigger.wait_value = value;
    wait_list[0].trigger.test_type = XSyncPositiveTransition;
    printf("XSyncAwait call\n");
    XSyncAwait(display, wait_list, 1);
    printf("XSyncAwait return\n");
    printf("XSync call\n");
    XSync(display, 0);
    printf("XSync return\n");
    return 0;
  }
  {
    Display *display = XOpenDisplay(NULL);
    if (!display) {
      abort();
    }
    int major = 3;
    int minor = 1;
    XSyncInitialize(display, &major, &minor);
    XSyncValue value;
    XSyncIntToValue(&value, 0);
    XSyncCounter counter = XSyncCreateCounter(display, value);
    static XSyncWaitCondition wait_list[1];
    XSyncIntToValue(&value, 123);
    wait_list[0].trigger.counter = counter;
    wait_list[0].trigger.value_type = XSyncAbsolute;
    wait_list[0].trigger.wait_value = value;
    wait_list[0].trigger.test_type = XSyncPositiveTransition;
    printf("XSyncAwait call\n");
    XSyncAwait(display, wait_list, 1);
    printf("XSyncAwait return\n");
    printf("XSync call\n");
    XSync(display, 0);
    printf("XSync return\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ae <main+0x2e>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x3,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <XSyncInitialize@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <XSyncIntToValue@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <XSyncCreateCounter@plt>
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x7b,%esi
call   1080 <XSyncIntToValue@plt>
mov    -0x28(%rbp),%rax
mov    %rax,0x2e86(%rip)
mov    0x2dcf(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2e6d(%rip)
mov    -0x20(%rbp),%rax
mov    %rax,0x2e5a(%rip)
mov    0x2dc3(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2e41(%rip)
lea    0xdca(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0x2e2a(%rip),%rsi
mov    $0x1,%edx
call   10a0 <XSyncAwait@plt>
lea    0xdba(%rip),%rdi
call   1060 <printf@plt>
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1090 <XSync@plt>
lea    0xdb6(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1070 <XOpenDisplay@plt>
test   %rax,%rax
je     1279 <main+0xf9>
mov    %rax,%rbx
movl   $0x3,0x4(%rsp)
movl   $0x1,(%rsp)
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <XSyncInitialize@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <XSyncIntToValue@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <XSyncCreateCounter@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x7b,%esi
call   1080 <XSyncIntToValue@plt>
mov    %r15,0x2e9a(%rip)
lea    0x2e7b(%rip),%r14
mov    0x2ddc(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2e7a(%rip)
mov    0x8(%rsp),%rax
mov    %rax,0x2e66(%rip)
mov    0x2dcf(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x2e4d(%rip)
lea    0xdd6(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   10a0 <XSyncAwait@plt>
lea    0xdca(%rip),%rdi
call   1040 <puts@plt>
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <XSync@plt>
lea    0xdc5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i8*, i8*, i8*, i8* }
@main.wait_list = internal global [1 x %struct.TYPE_5__] zeroinitializer
@XSyncAbsolute = global i8* null
@XSyncPositiveTransition = global i8* null
@.str = [17 x i8] c"XSyncAwait call\0A\00"
@.str.1 = [19 x i8] c"XSyncAwait return\0A\00"
@.str.2 = [12 x i8] c"XSync call\0A\00"
@.str.3 = [14 x i8] c"XSync return\0A\00"
@main.wait_list.4 = internal global [1 x %struct.TYPE_5__] zeroinitializer
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %1
%12 = call i32* @XOpenDisplay(i32* null)
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %0
store i32 3, i32* %3
store i32 1, i32* %4
%18 = load i32*, i32** %2
%19 = call i32 @XSyncInitialize(i32* %18, i32* %3, i32* %4)
%20 = call i32 @XSyncIntToValue(i8** %5, i32 0)
%21 = load i32*, i32** %2
%22 = load i8*, i8** %5
%23 = call i8* @XSyncCreateCounter(i32* %21, i8* %22)
store i8* %23, i8** %6
%24 = call i32 @XSyncIntToValue(i8** %5, i32 123)
%25 = load i8*, i8** %6
store i8* %25, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 3)
%26 = load i8*, i8** @XSyncAbsolute
store i8* %26, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 2)
%27 = load i8*, i8** %5
store i8* %27, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 1)
%28 = load i8*, i8** @XSyncPositiveTransition
store i8* %28, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 0)
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%30 = load i32*, i32** %2
%31 = call i32 @XSyncAwait(i32* %30, %struct.TYPE_5__* getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0), i32 1)
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32*, i32** %2
%35 = call i32 @XSync(i32* %34, i32 0)
%36 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i8*, i8*, i8*, i8* }
@main.wait_list = internal global [1 x %struct.TYPE_5__] zeroinitializer
@XSyncAbsolute = global i8* null
@XSyncPositiveTransition = global i8* null
@str = [16 x i8] c"XSyncAwait call\00"
@str.5 = [18 x i8] c"XSyncAwait return\00"
@str.6 = [11 x i8] c"XSync call\00"
@str.7 = [13 x i8] c"XSync return\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = tail call i32* @XOpenDisplay(i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %0
%9 = bitcast i32* %1 to i8*
store i32 3, i32* %1
%10 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%11 = call i32 @XSyncInitialize(i32* %4, i32* %1, i32* %2)
%12 = bitcast i8** %3 to i8*
%13 = call i32 @XSyncIntToValue(i8** %3, i32 0)
%14 = load i8*, i8** %3
%15 = call i8* @XSyncCreateCounter(i32* %4, i8* %14)
%16 = call i32 @XSyncIntToValue(i8** %3, i32 123)
store i8* %15, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 3)
%17 = load i8*, i8** @XSyncAbsolute
store i8* %17, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 2)
%18 = load i8*, i8** %3
store i8* %18, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 1)
%19 = load i8*, i8** @XSyncPositiveTransition
store i8* %19, i8** getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0, i32 0, i32 0)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%21 = call i32 @XSyncAwait(i32* %4, %struct.TYPE_5__* getelementptr inbounds ([1 x %struct.TYPE_5__], [1 x %struct.TYPE_5__]* @main.wait_list, i64 0, i64 0), i32 1)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
%24 = call i32 @XSync(i32* %4, i32 0)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}