#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*/ printf(char *, ...);
int safety(int **, int **, int *, int, int, int *);
int banker(int allocation[10][10], int need[10][10], int available[10], int n,
           int m) {
  int safe;
  int sequence[10];
  int i;
  safe = safety(allocation, need, available, n, m, sequence);
  if (safe != 0) {
    printf("\n");
    for (i = 0; i < n; i++) {
      printf("%d ", sequence[i]);
    }
    printf("\nA safe sequence exists.");
    return 1;
  } else {
    printf("\nNo safe sequence exists.");
    return 0;
  }
}


x86 assembly (clang, -O0):
<banker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    -0x60(%rbp),%r9
call   1040 <safety@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11c3 <banker+0xa3>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a9 <banker+0x89>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1179 <banker+0x59>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <banker+0xb8>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<banker>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %ecx,%ebp
mov    %rsp,%r9
call   1050 <safety@plt>
test   %eax,%eax
je     1188 <banker+0x58>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%r14d
lea    0xea3(%rip),%r15
test   %ebp,%ebp
jle    1192 <banker+0x62>
mov    %ebp,%ebx
lea    0xe92(%rip),%r12
xor    %ebp,%ebp
mov    (%rsp,%rbp,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <banker+0x40>
jmp    1192 <banker+0x62>
xor    %r14d,%r14d
lea    0xe8b(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [25 x i8] c"\0AA safe sequence exists.\00"
@.str.3 = [26 x i8] c"\0ANo safe sequence exists.\00"
define i32 @banker([10 x i32]* %0, [10 x i32]* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca [10 x i32]*
%8 = alloca [10 x i32]*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [10 x i32]
%14 = alloca i32
store [10 x i32]* %0, [10 x i32]** %7
store [10 x i32]* %1, [10 x i32]** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load [10 x i32]*, [10 x i32]** %7
%16 = bitcast [10 x i32]* %15 to i32**
%17 = load [10 x i32]*, [10 x i32]** %8
%18 = bitcast [10 x i32]* %17 to i32**
%19 = load i32*, i32** %9
%20 = load i32, i32* %10
%21 = load i32, i32* %11
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 0
%23 = call i32 @safety(i32** %16, i32** %18, i32* %19, i32 %20, i32 %21, i32* %22)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %5
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %14
br label %28
28: ; preds = %38, %26
%29 = load i32, i32* %14
%30 = load i32, i32* %10
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28
%33 = load i32, i32* %14
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %32
%39 = load i32, i32* %14
%40 = add nsw i32 %39, 1
store i32 %40, i32* %14
br label %28
41: ; preds = %28
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %45
43: ; preds = %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %45
45: ; preds = %43, %41
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [25 x i8] c"\0AA safe sequence exists.\00"
@.str.3 = [26 x i8] c"\0ANo safe sequence exists.\00"
define i32 @banker([10 x i32]* %0, [10 x i32]* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca [10 x i32]
%7 = bitcast [10 x i32]* %6 to i8*
%8 = bitcast [10 x i32]* %0 to i32**
%9 = bitcast [10 x i32]* %1 to i32**
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%11 = call i32 @safety(i32** %8, i32** %9, i32* %2, i32 %3, i32 %4, i32* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %5
%14 = call i32 @putchar(i32 10)
%15 = icmp sgt i32 %3, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %5, %13
%26 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), %18 ]
%27 = phi i32 [ 1, %13 ], [ 0, %5 ], [ 1, %18 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %26)
ret i32 %27
}