#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*/ duergar(int, int);
int /*<<< orphan*/ niceprint(char *);
int /*<<< orphan*/ putchar(char);
void patrol(int num) {
  int i;
  int count = d(4) + 2;
  niceprint("The party encounters one or more duergar patrols.  In each "
            "patrol, all but two duegar are invisible.  "
            "Invisible duergar can sneak up on a character by making a "
            "Dexterity (Stealth) check with advantage, "
            "contested by the character's passive Wisdom (Perception) score.");
  (void)putchar('\n');
  for (i = 0; i < num; num--) {
    duergar(count, count - 2);
  }
}


x86 assembly (clang, -O0):
<patrol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <d@plt>
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
lea    0xe9e(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a0 <patrol+0x60>
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x2,%esi
call   1050 <duergar@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <patrol+0x38>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patrol>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0x4,%edi
call   1040 <d@plt>
mov    %eax,%r14d
lea    0xea6(%rip),%rdi
call   1060 <niceprint@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
jle    1192 <patrol+0x52>
mov    %r14d,%ebp
add    $0x2,%ebp
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <duergar@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1180 <patrol+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [266 x i8] c"The party encounters one or more duergar patrols. In each patrol, all but two duegar are invisible. Invisible duergar can sneak up on a character by making a Dexterity (Stealth) check with advantage, contested by the character's passive Wisdom (Perception) score.\00"
define void @patrol(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @d(i32 4)
%6 = add nsw i32 %5, 2
store i32 %6, i32* %4
%7 = call i32 @niceprint(i8* getelementptr inbounds ([266 x i8], [266 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %3
br label %9
9: ; preds = %18, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 2
%17 = call i32 @duergar(i32 %14, i32 %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = add nsw i32 %19, -1
store i32 %20, i32* %2
br label %9
21: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [266 x i8] c"The party encounters one or more duergar patrols. In each patrol, all but two duegar are invisible. Invisible duergar can sneak up on a character by making a Dexterity (Stealth) check with advantage, contested by the character's passive Wisdom (Perception) score.\00"
define void @patrol(i32 %0) {
%2 = tail call i32 @d(i32 4)
%3 = add nsw i32 %2, 2
%4 = tail call i32 @niceprint(i8* getelementptr inbounds ([266 x i8], [266 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @putchar(i8 signext 10)
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %12
7: ; preds = %1, %7
%8 = phi i32 [ %10, %7 ], [ %0, %1 ]
%9 = tail call i32 @duergar(i32 %3, i32 %2)
%10 = add nsw i32 %8, -1
%11 = icmp ugt i32 %8, 1
br i1 %11, label %7, label %12
12: ; preds = %7, %1
ret void
}