#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 *, long, long);
long switchv(long);
int main(int argc, char *argv[]) {
  long vals[8];
  long i;
  for (i = 0; i < 8; i++) {
    vals[i] = switchv(i + -1);
    printf("idx = %ld, val = 0x%lx\n", i + -1, vals[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x58(%rbp)
cmpq   $0x8,-0x58(%rbp)
jge    1190 <main+0x70>
mov    -0x58(%rbp),%rdi
add    $0xffffffffffffffff,%rdi
call   1040 <switchv@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,-0x50(%rbp,%rax,8)
mov    -0x58(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rdx
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    113e <main+0x1e>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xffffffffffffffff,%rdi
call   1040 <switchv@plt>
lea    0xecc(%rip),%rbx
mov    %rbx,%rdi
mov    $0xffffffffffffffff,%rsi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <switchv@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <switchv@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x2,%edi
call   1040 <switchv@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x3,%edi
call   1040 <switchv@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x4,%edi
call   1040 <switchv@plt>
mov    $0x4,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x5,%edi
call   1040 <switchv@plt>
mov    $0x5,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    $0x6,%edi
call   1040 <switchv@plt>
mov    $0x6,%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"idx = %ld, val = 0x%lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i64]
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
br label %8
8: ; preds = %23, %2
%9 = load i64, i64* %7
%10 = icmp slt i64 %9, 8
br i1 %10, label %11, label %26
11: ; preds = %8
%12 = load i64, i64* %7
%13 = add nsw i64 %12, -1
%14 = call i64 @switchv(i64 %13)
%15 = load i64, i64* %7
%16 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 %15
store i64 %14, i64* %16
%17 = load i64, i64* %7
%18 = add nsw i64 %17, -1
%19 = load i64, i64* %7
%20 = getelementptr inbounds [8 x i64], [8 x i64]* %6, i64 0, i64 %19
%21 = load i64, i64* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 %18, i64 %21)
br label %23
23: ; preds = %11
%24 = load i64, i64* %7
%25 = add nsw i64 %24, 1
store i64 %25, i64* %7
br label %8
26: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"idx = %ld, val = 0x%lx\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @switchv(i64 -1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 -1, i64 %3)
%5 = tail call i64 @switchv(i64 0)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 0, i64 %5)
%7 = tail call i64 @switchv(i64 1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 1, i64 %7)
%9 = tail call i64 @switchv(i64 2)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 2, i64 %9)
%11 = tail call i64 @switchv(i64 3)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 3, i64 %11)
%13 = tail call i64 @switchv(i64 4)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 4, i64 %13)
%15 = tail call i64 @switchv(i64 5)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 5, i64 %15)
%17 = tail call i64 @switchv(i64 6)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i64 6, i64 %17)
ret i32 0
}