#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*/ request;

/* Variables and functions */
int /*<<< orphan*/ generate_word(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int rand();
size_t sprintf(char *, char *, char *);
void generate_request(int method, size_t *size, char *request) {
  if (method <= 0 || method > 3) {
    method = rand() % 10;
    if (method < 6)
      method = 1;
    else if (method == 9)
      method = 3;
    else
      method = 2;
  }
  char *word = malloc(10);
  generate_word(word);
  memset(request, 0, sizeof(request));
  switch (method) {
  case 1:
    *size = sprintf(request, "FIND %s", word);
    break;
  case 2:
    *size = sprintf(request, "INSERT %s", word);
    break;
  case 3:
    *size = sprintf(request, "REMOVE %s", word);
    break;
  }
  printf("%s\n", request);
}


x86 assembly (clang, -O0):
<generate_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1187 <generate_request+0x27>
cmpl   $0x3,-0x4(%rbp)
jle    11d6 <generate_request+0x76>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
cmpl   $0x6,-0x4(%rbp)
jge    11af <generate_request+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <generate_request+0x71>
cmpl   $0x9,-0x4(%rbp)
jne    11c5 <generate_request+0x65>
movl   $0x3,-0x4(%rbp)
jmp    11cc <generate_request+0x6c>
movl   $0x2,-0x4(%rbp)
jmp    11d1 <generate_request+0x71>
jmp    11d6 <generate_request+0x76>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <generate_word@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1233 <generate_request+0xd3>
jmp    1211 <generate_request+0xb1>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1256 <generate_request+0xf6>
jmp    1222 <generate_request+0xc2>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
je     1279 <generate_request+0x119>
jmp    1297 <generate_request+0x137>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdbe(%rip),%rsi
call   1070 <sprintf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1297 <generate_request+0x137>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xda3(%rip),%rsi
call   1070 <sprintf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1297 <generate_request+0x137>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd8a(%rip),%rsi
call   1070 <sprintf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rsi
lea    0xd7a(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_request>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffc,%eax
ja     11cf <generate_request+0x6f>
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0xa,%edi
cmp    $0x5,%ebx
jg     120b <generate_request+0xab>
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <generate_word@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    0xe33(%rip),%rsi
jmp    123f <generate_request+0xdf>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <generate_word@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
cmp    $0x3,%ebx
je     122f <generate_request+0xcf>
cmp    $0x2,%ebx
je     1238 <generate_request+0xd8>
cmp    $0x1,%ebx
jne    124d <generate_request+0xed>
lea    0xdf7(%rip),%rsi
jmp    123f <generate_request+0xdf>
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <generate_word@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
cmp    $0x9,%ebx
jne    1238 <generate_request+0xd8>
lea    0xddc(%rip),%rsi
jmp    123f <generate_request+0xdf>
lea    0xdc9(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
call   1070 <sprintf@plt>
mov    %rax,(%r14)
lea    0xdc8(%rip),%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"FIND %s\00"
@.str.1 = [10 x i8] c"INSERT %s\00"
@.str.2 = [10 x i8] c"REMOVE %s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @generate_request(i32 %0, i64* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %4
store i64* %1, i64** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 3
br i1 %12, label %13, label %26
13: ; preds = %10, %3
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 10
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 6
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %4
br label %25
19: ; preds = %13
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 9
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 3, i32* %4
br label %24
23: ; preds = %19
store i32 2, i32* %4
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %18
br label %26
26: ; preds = %25, %10
%27 = call i8* @malloc(i32 10)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i32 @generate_word(i8* %28)
%30 = load i8*, i8** %6
%31 = call i32 @memset(i8* %30, i32 0, i32 8)
%32 = load i32, i32* %4
switch i32 %32, label %48 [
i32 1, label %33
i32 2, label %38
i32 3, label %43
]
33: ; preds = %26
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i64 @sprintf(i8* %34, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i64*, i64** %5
store i64 %36, i64* %37
br label %48
38: ; preds = %26
%39 = load i8*, i8** %6
%40 = load i8*, i8** %7
%41 = call i64 @sprintf(i8* %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = load i64*, i64** %5
store i64 %41, i64* %42
br label %48
43: ; preds = %26
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = call i64 @sprintf(i8* %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = load i64*, i64** %5
store i64 %46, i64* %47
br label %48
48: ; preds = %26, %43, %38, %33
%49 = load i8*, i8** %6
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %49)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"FIND %s\00"
@.str.1 = [10 x i8] c"INSERT %s\00"
@.str.2 = [10 x i8] c"REMOVE %s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @generate_request(i32 %0, i64* nocapture writeonly %1, i8* %2) {
%4 = add i32 %0, -4
%5 = icmp ult i32 %4, -3
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = icmp slt i32 %8, 6
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%12 = tail call i32 @generate_word(i8* %11)
%13 = tail call i32 @memset(i8* %2, i32 0, i32 8)
br label %23
14: ; preds = %6
%15 = icmp eq i32 %8, 9
%16 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%17 = tail call i32 @generate_word(i8* %16)
%18 = tail call i32 @memset(i8* %2, i32 0, i32 8)
br i1 %15, label %29, label %26
19: ; preds = %3
%20 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%21 = tail call i32 @generate_word(i8* %20)
%22 = tail call i32 @memset(i8* %2, i32 0, i32 8)
switch i32 %0, label %34 [
i32 1, label %23
i32 2, label %26
i32 3, label %29
]
23: ; preds = %10, %19
%24 = phi i8* [ %11, %10 ], [ %20, %19 ]
%25 = tail call i64 @sprintf(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %32
26: ; preds = %14, %19
%27 = phi i8* [ %20, %19 ], [ %16, %14 ]
%28 = tail call i64 @sprintf(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %32
29: ; preds = %14, %19
%30 = phi i8* [ %20, %19 ], [ %16, %14 ]
%31 = tail call i64 @sprintf(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %23, %26, %29
%33 = phi i64 [ %31, %29 ], [ %28, %26 ], [ %25, %23 ]
store i64 %33, i64* %1
br label %34
34: ; preds = %32, %19
%35 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
ret void
}