#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 atoi(char *);
int /*<<< orphan*/ printf(char *, unsigned long long, ...);
int main(int argc, char *argv[]) {
  int lgTableSize = 7;
  unsigned long long tableSize;
  unsigned long long NUPDATE;
  if (argc >= 2) {
    lgTableSize = atoi(argv[1]);
  }
  tableSize = 1 << lgTableSize;
  NUPDATE = tableSize * 4;
  printf("TableSize  = %llu\n", tableSize);
  printf("NumUpdates = %llu\n", NUPDATE);
  unsigned long long temp = 0x1ULL;
  unsigned long long index = 0;
  int i;
  for (i = 0; i < NUPDATE; i++) {
    temp = (temp << 1) ^ (((long long)temp < 0) ? 0x0000000000000007ULL : 0);
    index = temp & (tableSize - 1);
    printf("%llu %llu\n", index, temp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1157 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1215 <main+0xf5>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    -0x30(%rbp),%rsi
xor    %ecx,%ecx
mov    $0x7,%edx
cmp    $0x0,%rsi
cmovl  %rdx,%rcx
xor    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ae <main+0x8e>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x7,%ecx
cmp    $0x2,%edi
jl     113d <main+0x1d>
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%r14
lea    0x0(,%r14,4),%r15
lea    0xeaa(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffffffffffff,%r14
cmp    $0x2,%r15
mov    $0x1,%ebx
cmovb  %rbx,%r15
lea    0xe9d(%rip),%r12
nopl   0x0(%rax)
lea    (%rbx,%rbx,1),%rax
sar    $0x3f,%rbx
and    $0x7,%ebx
xor    %rax,%rbx
mov    %rbx,%rsi
and    %r14,%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffffffffffff,%r15
jne    1190 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"TableSize = %llu\0A\00"
@.str.1 = [19 x i8] c"NumUpdates = %llu\0A\00"
@.str.2 = [11 x i8] c"%llu %llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 7, i32* %6
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %19
19: ; preds = %14, %2
%20 = load i32, i32* %6
%21 = shl i32 1, %20
%22 = sext i32 %21 to i64
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = mul i64 %23, 4
store i64 %24, i64* %8
%25 = load i64, i64* %7
%26 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = load i64, i64* %8
%28 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %27)
store i64 1, i64* %9
store i64 0, i64* %10
store i32 0, i32* %11
br label %29
29: ; preds = %49, %19
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = load i64, i64* %8
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %52
34: ; preds = %29
%35 = load i64, i64* %9
%36 = shl i64 %35, 1
%37 = load i64, i64* %9
%38 = icmp slt i64 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i64 7, i64 0
%41 = xor i64 %36, %40
store i64 %41, i64* %9
%42 = load i64, i64* %9
%43 = load i64, i64* %7
%44 = sub i64 %43, 1
%45 = and i64 %42, %44
store i64 %45, i64* %10
%46 = load i64, i64* %10
%47 = load i64, i64* %9
%48 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %46, i64 %47)
br label %49
49: ; preds = %34
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %29
52: ; preds = %29
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [19 x i8] c"TableSize = %llu\0A\00"
@.str.1 = [19 x i8] c"NumUpdates = %llu\0A\00"
@.str.2 = [11 x i8] c"%llu %llu\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 7, %2 ]
%10 = shl nuw i32 1, %9
%11 = sext i32 %10 to i64
%12 = shl nsw i64 %11, 2
%13 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %11)
%14 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %12)
%15 = add nsw i64 %11, -1
%16 = call i64 @llvm.umax.i64(i64 %12, i64 1)
br label %17
17: ; preds = %8, %17
%18 = phi i64 [ 0, %8 ], [ %26, %17 ]
%19 = phi i64 [ 1, %8 ], [ %23, %17 ]
%20 = shl i64 %19, 1
%21 = icmp slt i64 %19, 0
%22 = select i1 %21, i64 7, i64 0
%23 = xor i64 %22, %20
%24 = and i64 %23, %15
%25 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %24, i64 %23)
%26 = add nuw i64 %18, 1
%27 = icmp eq i64 %26, %16
br i1 %27, label %28, label %17
28: ; preds = %17
ret i32 0
}