#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 unsigned long __u32;

/* Variables and functions */
int /*<<< orphan*/ local_irq_enable();
unsigned long local_irq_save();
unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
                            unsigned long new) {
  __u32 retval;
  unsigned long flags;
  flags = local_irq_save();
  retval = *m;
  if (retval == old)
    *m = new;
  do {
    if ((flags & 0x000000f0) != 0x000000f0)
      local_irq_enable();
  } while (0);
  return retval;
}


x86 assembly (clang, -O0):
<__cmpxchg_u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <local_irq_save@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1165 <__cmpxchg_u32+0x45>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    116a <__cmpxchg_u32+0x4a>
mov    -0x28(%rbp),%rax
and    $0xf0,%rax
cmp    $0xf0,%rax
je     1187 <__cmpxchg_u32+0x67>
mov    $0x0,%al
call   1040 <local_irq_enable@plt>
jmp    118c <__cmpxchg_u32+0x6c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__cmpxchg_u32>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <local_irq_save@plt>
movslq (%rbx),%r15
cmp    %r12,%r15
jne    1143 <__cmpxchg_u32+0x23>
mov    %r14d,(%rbx)
not    %eax
test   $0xf0,%al
je     1150 <__cmpxchg_u32+0x30>
xor    %eax,%eax
call   1040 <local_irq_enable@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @__cmpxchg_u32(i32* %0, i64 %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = call i64 (...) @local_irq_save()
store i64 %9, i64* %8
%10 = load i32*, i32** %4
%11 = load volatile i32, i32* %10
%12 = sext i32 %11 to i64
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = load i64, i64* %5
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i64, i64* %6
%18 = trunc i64 %17 to i32
%19 = load i32*, i32** %4
store volatile i32 %18, i32* %19
br label %20
20: ; preds = %16, %3
br label %21
21: ; preds = %20
%22 = load i64, i64* %8
%23 = and i64 %22, 240
%24 = icmp ne i64 %23, 240
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (...) @local_irq_enable()
br label %27
27: ; preds = %25, %21
br label %28
28: ; preds = %27
%29 = load i64, i64* %7
ret i64 %29
}

LLVM IR (-O2):
define i64 @__cmpxchg_u32(i32* %0, i64 %1, i64 %2) {
%4 = tail call i64 (...) @local_irq_save()
%5 = load volatile i32, i32* %0
%6 = sext i32 %5 to i64
%7 = icmp eq i64 %6, %1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = trunc i64 %2 to i32
store volatile i32 %9, i32* %0
br label %10
10: ; preds = %3, %8
%11 = and i64 %4, 240
%12 = icmp eq i64 %11, 240
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (...) @local_irq_enable()
br label %15
15: ; preds = %13, %10
ret i64 %6
}