#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 d(int);
int /*<<< orphan*/ magictableb();
int /*<<< orphan*/ magictablec();
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ printf(char *, int);
void ambushlair(unsigned d20) {
  int i;
  unsigned d4;
  if (d20 < 11)
    return;
  niceprint("This ambush has occurred in the monster's lair.\n\n");
  if (d20 < 13)
    niceprint("The lair contains a humanoid skeleton or corpse "
              "clutching a salvagable, non-magical weapon.\n\n");
  else if (d20 < 15)
    niceprint("The lair contains a humanoid skeleton or corpse "
              "wearing a salvagable suit of non-magical armor.\n\n");
  else if (d20 < 18)
    printf("The lair contains %d 50gp gem(s)\n", d(6));
  else if (d20 < 19) {
    niceprint("The lair contains a humanoid skeleton or corpse "
              "carrying a magical item.\n\n");
    magictableb();
  } else {
    niceprint("The lair contains:\n\n");
    printf("%d 50gp gem(s)\n", (d(6) + d(6)));
    for (i = 0, d4 = d(4); i < d4; i++)
      magictablec();
  }
}


x86 assembly (clang, -O0):
<ambushlair>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xb,-0x4(%rbp)
jae    116a <ambushlair+0x1a>
jmp    1272 <ambushlair+0x122>
lea    0xe8f(%rip),%rdi
call   1060 <niceprint@plt>
cmpl   $0xd,-0x4(%rbp)
jae    1191 <ambushlair+0x41>
lea    0xeab(%rip),%rdi
call   1060 <niceprint@plt>
jmp    1272 <ambushlair+0x122>
cmpl   $0xf,-0x4(%rbp)
jae    11ac <ambushlair+0x5c>
lea    0xeee(%rip),%rdi
call   1060 <niceprint@plt>
jmp    126d <ambushlair+0x11d>
cmpl   $0x12,-0x4(%rbp)
jae    11d3 <ambushlair+0x83>
mov    $0x6,%edi
call   1030 <d@plt>
mov    %eax,%esi
lea    0xf29(%rip),%rdi
call   1040 <printf@plt>
jmp    1268 <ambushlair+0x118>
cmpl   $0x13,-0x4(%rbp)
jae    11f5 <ambushlair+0xa5>
lea    0xf30(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0x0,%al
call   1070 <magictableb@plt>
jmp    1263 <ambushlair+0x113>
lea    0xf63(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0x6,%edi
call   1030 <d@plt>
mov    %eax,-0x10(%rbp)
mov    $0x6,%edi
call   1030 <d@plt>
mov    -0x10(%rbp),%esi
add    %eax,%esi
lea    0xee0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x4,%edi
call   1030 <d@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    125e <ambushlair+0x10e>
mov    $0x0,%al
call   1050 <magictablec@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    123d <ambushlair+0xed>
jmp    1263 <ambushlair+0x113>
jmp    1268 <ambushlair+0x118>
jmp    126d <ambushlair+0x11d>
jmp    1272 <ambushlair+0x122>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ambushlair>:
push   %rbx
cmp    $0xb,%edi
jae    1158 <ambushlair+0x8>
pop    %rbx
ret
mov    %edi,%ebx
lea    0xe9f(%rip),%rdi
call   1060 <niceprint@plt>
cmp    $0xc,%ebx
ja     1178 <ambushlair+0x28>
lea    0xec0(%rip),%rdi
pop    %rbx
jmp    1060 <niceprint@plt>
cmp    $0xe,%ebx
ja     118a <ambushlair+0x3a>
lea    0xf0c(%rip),%rdi
pop    %rbx
jmp    1060 <niceprint@plt>
cmp    $0x11,%ebx
ja     11a8 <ambushlair+0x58>
mov    $0x6,%edi
call   1030 <d@plt>
lea    0xf52(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1040 <printf@plt>
cmp    $0x12,%ebx
jne    11c1 <ambushlair+0x71>
lea    0xf60(%rip),%rdi
call   1060 <niceprint@plt>
xor    %eax,%eax
pop    %rbx
jmp    1070 <magictableb@plt>
lea    0xf97(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0x6,%edi
call   1030 <d@plt>
mov    %eax,%ebx
mov    $0x6,%edi
call   1030 <d@plt>
add    %eax,%ebx
lea    0xf18(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    $0x4,%edi
call   1030 <d@plt>
test   %eax,%eax
je     1156 <ambushlair+0x6>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <magictablec@plt>
add    $0xffffffff,%ebx
jne    1210 <ambushlair+0xc0>
jmp    1156 <ambushlair+0x6>

LLVM IR (-O0):
@.str = [50 x i8] c"This ambush has occurred in the monster's lair.\0A\0A\00"
@.str.1 = [94 x i8] c"The lair contains a humanoid skeleton or corpse clutching a salvagable, non-magical weapon.\0A\0A\00"
@.str.2 = [98 x i8] c"The lair contains a humanoid skeleton or corpse wearing a salvagable suit of non-magical armor.\0A\0A\00"
@.str.3 = [34 x i8] c"The lair contains %d 50gp gem(s)\0A\00"
@.str.4 = [75 x i8] c"The lair contains a humanoid skeleton or corpse carrying a magical item.\0A\0A\00"
@.str.5 = [21 x i8] c"The lair contains:\0A\0A\00"
@.str.6 = [16 x i8] c"%d 50gp gem(s)\0A\00"
define void @ambushlair(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp ult i32 %5, 11
br i1 %6, label %7, label %8
7: ; preds = %1
br label %51
8: ; preds = %1
%9 = call i32 @niceprint(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %2
%11 = icmp ult i32 %10, 13
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @niceprint(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.1, i64 0, i64 0))
br label %51
14: ; preds = %8
%15 = load i32, i32* %2
%16 = icmp ult i32 %15, 15
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @niceprint(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0))
br label %50
19: ; preds = %14
%20 = load i32, i32* %2
%21 = icmp ult i32 %20, 18
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @d(i32 6)
%24 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %49
25: ; preds = %19
%26 = load i32, i32* %2
%27 = icmp ult i32 %26, 19
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @niceprint(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 (...) @magictableb()
br label %48
31: ; preds = %25
%32 = call i32 @niceprint(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @d(i32 6)
%34 = call i32 @d(i32 6)
%35 = add nsw i32 %33, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %35)
store i32 0, i32* %3
%37 = call i32 @d(i32 4)
store i32 %37, i32* %4
br label %38
38: ; preds = %44, %31
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = icmp ult i32 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = call i32 (...) @magictablec()
br label %44
44: ; preds = %42
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %38
47: ; preds = %38
br label %48
48: ; preds = %47, %28
br label %49
49: ; preds = %48, %22
br label %50
50: ; preds = %49, %17
br label %51
51: ; preds = %7, %50, %12
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"This ambush has occurred in the monster's lair.\0A\0A\00"
@.str.1 = [94 x i8] c"The lair contains a humanoid skeleton or corpse clutching a salvagable, non-magical weapon.\0A\0A\00"
@.str.2 = [98 x i8] c"The lair contains a humanoid skeleton or corpse wearing a salvagable suit of non-magical armor.\0A\0A\00"
@.str.3 = [34 x i8] c"The lair contains %d 50gp gem(s)\0A\00"
@.str.4 = [75 x i8] c"The lair contains a humanoid skeleton or corpse carrying a magical item.\0A\0A\00"
@.str.5 = [21 x i8] c"The lair contains:\0A\0A\00"
@.str.6 = [16 x i8] c"%d 50gp gem(s)\0A\00"
define void @ambushlair(i32 %0) {
%2 = icmp ult i32 %0, 11
br i1 %2, label %35, label %3
3: ; preds = %1
%4 = tail call i32 @niceprint(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%5 = icmp ult i32 %0, 13
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @niceprint(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.1, i64 0, i64 0))
br label %35
8: ; preds = %3
%9 = icmp ult i32 %0, 15
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @niceprint(i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0))
br label %35
12: ; preds = %8
%13 = icmp ult i32 %0, 18
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = tail call i32 @d(i32 6)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %35
17: ; preds = %12
%18 = icmp eq i32 %0, 18
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = tail call i32 @niceprint(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 (...) @magictableb()
br label %35
22: ; preds = %17
%23 = tail call i32 @niceprint(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%24 = tail call i32 @d(i32 6)
%25 = tail call i32 @d(i32 6)
%26 = add nsw i32 %25, %24
%27 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = tail call i32 @d(i32 4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %22, %30
%31 = phi i32 [ %33, %30 ], [ 0, %22 ]
%32 = tail call i32 (...) @magictablec()
%33 = add nuw i32 %31, 1
%34 = icmp eq i32 %33, %28
br i1 %34, label %35, label %30
35: ; preds = %30, %22, %6, %14, %19, %10, %1
ret void
}