#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*/ timeoutArray(int *, int, int const);
int /*<<< orphan*/ usleep(int const);
void permute(int *array, int *data, const int start, const int end, int index,
             int r, const int timeoutSec, const int delaybeforeMS,
             const int delayafterMS) {
  if (index == r) {
    usleep(delaybeforeMS * 1000);
    timeoutArray(data, r, timeoutSec);
    usleep(delayafterMS * 1000);
    timeoutArray(data, r, 30);
    return;
  }
  for (int i = start; i <= end && end - i + 1 >= r - index; i++) {
    data[index] = array[i];
    permute(array, data, i + 1, end, index + 1, r, timeoutSec, delaybeforeMS,
            delayafterMS);
  }
  return;
}


x86 assembly (clang, -O0):
<permute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    11a0 <permute+0x70>
imul   $0x3e8,0x18(%rbp),%edi
call   1050 <usleep@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x10(%rbp),%edx
call   1040 <timeoutArray@plt>
imul   $0x3e8,0x20(%rbp),%edi
call   1050 <usleep@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x1e,%edx
call   1040 <timeoutArray@plt>
jmp    1241 <permute+0x111>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x25(%rbp)
jg     11ce <permute+0x9e>
mov    -0x18(%rbp),%eax
sub    -0x24(%rbp),%eax
add    $0x1,%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
cmp    %ecx,%eax
setge  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11de <permute+0xae>
jmp    123c <permute+0x10c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%r9d
mov    0x10(%rbp),%r11d
mov    0x18(%rbp),%r10d
mov    0x20(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <permute@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <permute+0x76>
jmp    1241 <permute+0x111>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permute>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r14d
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,0x18(%rsp)
mov    0x80(%rsp),%r12d
mov    0x78(%rsp),%r13d
mov    0x70(%rsp),%ebx
mov    %r9d,%edx
sub    %r8d,%edx
mov    %edx,0x14(%rsp)
jne    11ae <permute+0x7e>
imul   $0x3e8,%r13d,%edi
mov    %rbx,%rbp
call   1050 <usleep@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1040 <timeoutArray@plt>
imul   $0x3e8,%r12d,%edi
call   1050 <usleep@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x1e,%edx
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <timeoutArray@plt>
mov    %r12,0x30(%rsp)
mov    %r14d,0x10(%rsp)
cmp    %ecx,%ebp
jg     1243 <permute+0x113>
mov    %r8d,%eax
movslq %r8d,%rdx
mov    %rdx,0x20(%rsp)
add    $0x1,%eax
mov    %eax,0xc(%rsp)
movslq %ebp,%rax
mov    %ecx,%r12d
sub    %ebp,%r12d
add    $0x1,%r12d
mov    0x18(%rsp),%rdx
lea    (%rdx,%rax,4),%r14
add    $0x1,%ebp
mov    %r15,0x28(%rsp)
cmp    0x14(%rsp),%r12d
jl     1243 <permute+0x113>
mov    (%r14),%eax
mov    0x20(%rsp),%rdx
mov    %eax,(%r15,%rdx,4)
sub    $0x8,%rsp
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ecx,%r15d
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
push   0x38(%rsp)
push   %r13
push   %rbx
call   1030 <permute@plt>
mov    %r15d,%ecx
mov    0x48(%rsp),%r15
add    $0x20,%rsp
add    $0x4,%r14
add    $0x1,%ebp
add    $0xffffffff,%r12d
jne    11f0 <permute+0xc0>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @permute(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %10
store i32* %1, i32** %11
store i32 %2, i32* %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
%20 = load i32, i32* %14
%21 = load i32, i32* %15
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %9
%24 = load i32, i32* %17
%25 = mul nsw i32 %24, 1000
%26 = call i32 @usleep(i32 %25)
%27 = load i32*, i32** %11
%28 = load i32, i32* %15
%29 = load i32, i32* %16
%30 = call i32 @timeoutArray(i32* %27, i32 %28, i32 %29)
%31 = load i32, i32* %18
%32 = mul nsw i32 %31, 1000
%33 = call i32 @usleep(i32 %32)
%34 = load i32*, i32** %11
%35 = load i32, i32* %15
%36 = call i32 @timeoutArray(i32* %34, i32 %35, i32 30)
br label %79
37: ; preds = %9
%38 = load i32, i32* %12
store i32 %38, i32* %19
br label %39
39: ; preds = %75, %37
%40 = load i32, i32* %19
%41 = load i32, i32* %13
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i32, i32* %13
%45 = load i32, i32* %19
%46 = sub nsw i32 %44, %45
%47 = add nsw i32 %46, 1
%48 = load i32, i32* %15
%49 = load i32, i32* %14
%50 = sub nsw i32 %48, %49
%51 = icmp sge i32 %47, %50
br label %52
52: ; preds = %43, %39
%53 = phi i1 [ false, %39 ], [ %51, %43 ]
br i1 %53, label %54, label %78
54: ; preds = %52
%55 = load i32*, i32** %10
%56 = load i32, i32* %19
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
%60 = load i32*, i32** %11
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
store i32 %59, i32* %63
%64 = load i32*, i32** %10
%65 = load i32*, i32** %11
%66 = load i32, i32* %19
%67 = add nsw i32 %66, 1
%68 = load i32, i32* %13
%69 = load i32, i32* %14
%70 = add nsw i32 %69, 1
%71 = load i32, i32* %15
%72 = load i32, i32* %16
%73 = load i32, i32* %17
%74 = load i32, i32* %18
br label %75
75: ; preds = %54
%76 = load i32, i32* %19
%77 = add nsw i32 %76, 1
store i32 %77, i32* %19
br label %39
78: ; preds = %52
br label %79
79: ; preds = %78, %23
ret void
}

LLVM IR (-O2):
define void @permute(i32* nocapture %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = icmp eq i32 %5, %4
br i1 %10, label %20, label %11
11: ; preds = %9
%12 = icmp sgt i32 %2, %3
br i1 %12, label %38, label %13
13: ; preds = %11
%14 = add i32 %3, 1
%15 = sub nsw i32 %5, %4
%16 = sext i32 %4 to i64
%17 = getelementptr inbounds i32, i32* %1, i64 %16
%18 = add nsw i32 %4, 1
%19 = sext i32 %2 to i64
br label %27
20: ; preds = %9
%21 = mul nsw i32 %7, 1000
%22 = tail call i32 @usleep(i32 %21)
%23 = tail call i32 @timeoutArray(i32* %1, i32 %5, i32 %6)
%24 = mul nsw i32 %8, 1000
%25 = tail call i32 @usleep(i32 %24)
%26 = tail call i32 @timeoutArray(i32* %1, i32 %5, i32 30)
br label %38
27: ; preds = %13, %32
%28 = phi i64 [ %19, %13 ], [ %35, %32 ]
%29 = trunc i64 %28 to i32
%30 = sub i32 %14, %29
%31 = icmp slt i32 %30, %15
br i1 %31, label %38, label %32
32: ; preds = %27
%33 = getelementptr inbounds i32, i32* %0, i64 %28
%34 = load i32, i32* %33
store i32 %34, i32* %17
%35 = add nsw i64 %28, 1
%36 = trunc i64 %35 to i32
tail call void @permute(i32* %0, i32* %1, i32 %36, i32 %3, i32 %18, i32 %5, i32 %6, i32 %7, i32 %8)
%37 = icmp eq i32 %14, %36
br i1 %37, label %38, label %27
38: ; preds = %32, %27, %11, %20
ret void
}