#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 rand();
void pick_site_twentyfour(long id[2]) {
  int dx = 0;
  int dy = 0;
  while ((dx == dy) && (dx == 0)) {
    dx = (rand() % 5) - 2;
    dy = (rand() % 5) - 2;
  }
  id[0] -= dx;
  id[1] += dy;
}


x86 assembly (clang, -O0):
<pick_site_twentyfour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x10(%rbp),%ecx
mov    %al,-0x11(%rbp)
jne    1145 <pick_site_twentyfour+0x35>
cmpl   $0x0,-0xc(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1155 <pick_site_twentyfour+0x45>
jmp    1184 <pick_site_twentyfour+0x74>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
sub    $0x2,%edx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
sub    $0x2,%edx
mov    %edx,-0x10(%rbp)
jmp    112a <pick_site_twentyfour+0x1a>
movslq -0xc(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movslq -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick_site_twentyfour>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebp
add    $0xfffffffe,%ebp
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
or     %ebp,%ecx
je     1120 <pick_site_twentyfour+0x10>
movslq %ebp,%rcx
sub    %rcx,(%rbx)
cltq
add    %rax,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @pick_site_twentyfour(i64* %0) {
%2 = alloca i64*
%3 = alloca i32
%4 = alloca i32
store i64* %0, i64** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 0
br label %12
12: ; preds = %9, %5
%13 = phi i1 [ false, %5 ], [ %11, %9 ]
br i1 %13, label %14, label %21
14: ; preds = %12
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 5
%17 = sub nsw i32 %16, 2
store i32 %17, i32* %3
%18 = call i32 (...) @rand()
%19 = srem i32 %18, 5
%20 = sub nsw i32 %19, 2
store i32 %20, i32* %4
br label %5
21: ; preds = %12
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = load i64*, i64** %2
%25 = getelementptr inbounds i64, i64* %24, i64 0
%26 = load i64, i64* %25
%27 = sub nsw i64 %26, %23
store i64 %27, i64* %25
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = load i64*, i64** %2
%31 = getelementptr inbounds i64, i64* %30, i64 1
%32 = load i64, i64* %31
%33 = add nsw i64 %32, %29
store i64 %33, i64* %31
ret void
}

LLVM IR (-O2):
define void @pick_site_twentyfour(i64* nocapture %0) {
br label %2
2: ; preds = %1, %2
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 5
%5 = add nsw i32 %4, -2
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 5
%8 = add nsw i32 %7, -2
%9 = or i32 %8, %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %2, label %11
11: ; preds = %2
%12 = sext i32 %5 to i64
%13 = load i64, i64* %0
%14 = sub nsw i64 %13, %12
store i64 %14, i64* %0
%15 = sext i32 %8 to i64
%16 = getelementptr inbounds i64, i64* %0, i64 1
%17 = load i64, i64* %16
%18 = add nsw i64 %17, %15
store i64 %18, i64* %16
ret void
}