#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_four(long id[2]) {
  switch (rand() % 4) {
  case 0:
    id[0] += 1;
    break;
  case 1:
    id[0] -= 1;
    break;
  case 2:
    id[1] += 1;
    break;
  case 3:
    id[1] -= 1;
    break;
  }
}


x86 assembly (clang, -O0):
<pick_site_four>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11a2 <pick_site_four+0x92>
mov    -0x10(%rbp),%rax
lea    0xeb2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11a2 <pick_site_four+0x92>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11a2 <pick_site_four+0x92>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
jmp    11a2 <pick_site_four+0x92>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pick_site_four>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cmp    $0x3,%eax
ja     1156 <pick_site_four+0x46>
mov    $0x1,%ecx
lea    0xec7(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
add    $0x8,%rbx
jmp    1153 <pick_site_four+0x43>
add    $0x8,%rbx
mov    $0xffffffffffffffff,%rcx
add    %rcx,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @pick_site_four(i64* %0) {
%2 = alloca i64*
store i64* %0, i64** %2
%3 = call i32 (...) @rand()
%4 = srem i32 %3, 4
switch i32 %4, label %25 [
i32 0, label %5
i32 1, label %10
i32 2, label %15
i32 3, label %20
]
5: ; preds = %1
%6 = load i64*, i64** %2
%7 = getelementptr inbounds i64, i64* %6, i64 0
%8 = load i64, i64* %7
%9 = add nsw i64 %8, 1
store i64 %9, i64* %7
br label %25
10: ; preds = %1
%11 = load i64*, i64** %2
%12 = getelementptr inbounds i64, i64* %11, i64 0
%13 = load i64, i64* %12
%14 = sub nsw i64 %13, 1
store i64 %14, i64* %12
br label %25
15: ; preds = %1
%16 = load i64*, i64** %2
%17 = getelementptr inbounds i64, i64* %16, i64 1
%18 = load i64, i64* %17
%19 = add nsw i64 %18, 1
store i64 %19, i64* %17
br label %25
20: ; preds = %1
%21 = load i64*, i64** %2
%22 = getelementptr inbounds i64, i64* %21, i64 1
%23 = load i64, i64* %22
%24 = sub nsw i64 %23, 1
store i64 %24, i64* %22
br label %25
25: ; preds = %1, %20, %15, %10, %5
ret void
}

LLVM IR (-O2):
define void @pick_site_four(i64* nocapture %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 4
switch i32 %3, label %14 [
i32 0, label %9
i32 1, label %4
i32 2, label %5
i32 3, label %7
]
4: ; preds = %1
br label %9
5: ; preds = %1
%6 = getelementptr inbounds i64, i64* %0, i64 1
br label %9
7: ; preds = %1
%8 = getelementptr inbounds i64, i64* %0, i64 1
br label %9
9: ; preds = %1, %4, %5, %7
%10 = phi i64* [ %8, %7 ], [ %6, %5 ], [ %0, %4 ], [ %0, %1 ]
%11 = phi i64 [ -1, %7 ], [ 1, %5 ], [ -1, %4 ], [ 1, %1 ]
%12 = load i64, i64* %10
%13 = add nsw i64 %12, %11
store i64 %13, i64* %10
br label %14
14: ; preds = %9, %1
ret void
}