#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 */

/* Variables and functions */
int /*<<< orphan*/ a_barrier();
void *a_ll_p(void volatile *);
int /*<<< orphan*/ a_post_llsc();
int /*<<< orphan*/ a_sc_p(void volatile *, void *);
void *a_cas_p(volatile void *p, void *t, void *s) {
  void *old;
  a_barrier();
  do
    old = a_ll_p(p);
  while (old == t && !a_sc_p(p, s));
  a_post_llsc();
  return old;
}


x86 assembly (clang, -O0):
<a_cas_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1040 <a_barrier@plt>
mov    -0x8(%rbp),%rdi
call   1060 <a_ll_p@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
jne    1193 <a_cas_p+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <a_sc_p@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    115b <a_cas_p+0x1b>
mov    $0x0,%al
call   1030 <a_post_llsc@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_cas_p>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <a_barrier@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <a_ll_p@plt>
cmp    %r14,%rax
jne    117e <a_cas_p+0x3e>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <a_sc_p@plt>
test   %eax,%eax
je     1160 <a_cas_p+0x20>
jmp    1181 <a_cas_p+0x41>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <a_post_llsc@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @a_cas_p(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = call i32 (...) @a_barrier()
br label %9
9: ; preds = %22, %3
%10 = load i8*, i8** %4
%11 = call i8* @a_ll_p(i8* %10)
store i8* %11, i8** %7
br label %12
12: ; preds = %9
%13 = load i8*, i8** %7
%14 = load i8*, i8** %5
%15 = icmp eq i8* %13, %14
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8*, i8** %6
%19 = call i32 @a_sc_p(i8* %17, i8* %18)
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
br label %22
22: ; preds = %16, %12
%23 = phi i1 [ false, %12 ], [ %21, %16 ]
br i1 %23, label %9, label %24
24: ; preds = %22
%25 = call i32 (...) @a_post_llsc()
%26 = load i8*, i8** %7
ret i8* %26
}

LLVM IR (-O2):
define i8* @a_cas_p(i8* %0, i8* readnone %1, i8* %2) {
%4 = tail call i32 (...) @a_barrier()
br label %5
5: ; preds = %8, %3
%6 = tail call i8* @a_ll_p(i8* %0)
%7 = icmp eq i8* %6, %1
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @a_sc_p(i8* %0, i8* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %5, label %11
11: ; preds = %5, %8
%12 = phi i8* [ %6, %5 ], [ %1, %8 ]
%13 = tail call i32 (...) @a_post_llsc()
ret i8* %12
}