#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 */
typedef int /*<<< orphan*/ tab;

/* Variables and functions */
int /*<<< orphan*/ message(char *);
scalar_t__ rand();
void random_message() {
  static char *tab[] = {
      "My turn: I'm thinking.",
      "Well, well...",
      "Now I will beat you.",
      "Surrender!",
      "Oh-oh.",
      "You have no chance.",
      "You have tired me.",
      "Do you think you are a Grandmaster?",
  };
  int n;
  n = (unsigned)rand() % (sizeof(tab) / sizeof(tab[0]));
  message(tab[n]);
}


x86 assembly (clang, -O0):
<random_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,%eax
and    $0x7,%rax
mov    %eax,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2efd(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1030 <message@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_message>:
push   %rax
xor    %eax,%eax
call   1040 <rand@plt>
and    $0x7,%eax
lea    0xece(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
pop    %rax
jmp    1030 <message@plt>

LLVM IR (-O0):
@random_message.tab = internal global [8 x i8*] [i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i32 0, i32 0)]
@.str = [23 x i8] c"My turn: I'm thinking.\00"
@.str.1 = [14 x i8] c"Well, well...\00"
@.str.2 = [21 x i8] c"Now I will beat you.\00"
@.str.3 = [11 x i8] c"Surrender!\00"
@.str.4 = [7 x i8] c"Oh-oh.\00"
@.str.5 = [20 x i8] c"You have no chance.\00"
@.str.6 = [19 x i8] c"You have tired me.\00"
@.str.7 = [36 x i8] c"Do you think you are a Grandmaster?\00"
define void @random_message() {
%1 = alloca i32
%2 = call i64 (...) @rand()
%3 = trunc i64 %2 to i32
%4 = zext i32 %3 to i64
%5 = urem i64 %4, 8
%6 = trunc i64 %5 to i32
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [8 x i8*], [8 x i8*]* @random_message.tab, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = call i32 @message(i8* %10)
ret void
}

LLVM IR (-O2):
@reltable.random_message = internal unnamed_addr constant [8 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.1 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.2 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.5 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.6 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([36 x i8]* @.str.7 to i64), i64 ptrtoint ([8 x i32]* @reltable.random_message to i64)) to i32)]
@.str = [23 x i8] c"My turn: I'm thinking.\00"
@.str.1 = [14 x i8] c"Well, well...\00"
@.str.2 = [21 x i8] c"Now I will beat you.\00"
@.str.3 = [11 x i8] c"Surrender!\00"
@.str.4 = [7 x i8] c"Oh-oh.\00"
@.str.5 = [20 x i8] c"You have no chance.\00"
@.str.6 = [19 x i8] c"You have tired me.\00"
@.str.7 = [36 x i8] c"Do you think you are a Grandmaster?\00"
define void @random_message() {
%1 = tail call i64 (...) @rand()
%2 = and i64 %1, 7
%3 = shl i64 %2, 2
%4 = call i8* @llvm.load.relative.i64(i8* bitcast ([8 x i32]* @reltable.random_message to i8*), i64 %3)
%5 = tail call i32 @message(i8* %4)
ret void
}