#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*/ printf(char *);
int SpinLock(int id) {
  unsigned long tmp;
  if (id < 0 || id > 63) {
    printf("bad spinlock id\n");
    return -1;
  }
  while (!(({
             unsigned long __v =
                 (*(volatile unsigned long *)((0x02640000 + 0x100 + id * 0x4)));
             __v;
           }) &
           0x1))
    ;
  return 0;
}


x86 assembly (clang, -O0):
<SpinLock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     112f <SpinLock+0x1f>
cmpl   $0x3f,-0x8(%rbp)
jle    1147 <SpinLock+0x37>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <SpinLock+0x82>
jmp    114c <SpinLock+0x3c>
mov    -0x8(%rbp),%eax
shl    $0x2,%eax
add    $0x2640100,%eax
cltq
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1186 <SpinLock+0x76>
jmp    118b <SpinLock+0x7b>
jmp    114c <SpinLock+0x3c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SpinLock>:
push   %rax
cmp    $0x3f,%edi
jbe    1129 <SpinLock+0x19>
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    %edi,%eax
lea    0x2640100(,%rax,4),%rax
02
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
testq  $0x1,(%rax)
je     1140 <SpinLock+0x30>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"bad spinlock id\0A\00"
define i32 @SpinLock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 63
br i1 %11, label %12, label %14
12: ; preds = %9, %1
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %29
14: ; preds = %9
br label %15
15: ; preds = %27, %14
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, 4
%18 = add nsw i32 40108288, %17
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i64*
%21 = load volatile i64, i64* %20
store i64 %21, i64* %5
%22 = load i64, i64* %5
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = and i64 %23, 1
%25 = icmp ne i64 %24, 0
%26 = xor i1 %25, true
br i1 %26, label %27, label %28
27: ; preds = %15
br label %15
28: ; preds = %15
store i32 0, i32* %2
br label %29
29: ; preds = %28, %12
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@str = [16 x i8] c"bad spinlock id\00"
define i32 @SpinLock(i32 %0) {
%2 = icmp ugt i32 %0, 63
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = shl nuw nsw i32 %0, 2
%5 = add nuw nsw i32 %4, 40108288
%6 = zext i32 %5 to i64
%7 = inttoptr i64 %6 to i64*
br label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %14
10: ; preds = %3, %10
%11 = load volatile i64, i64* %7
%12 = and i64 %11, 1
%13 = icmp eq i64 %12, 0
br i1 %13, label %10, label %14
14: ; preds = %10, %8
%15 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %15
}