#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*/ free(unsigned char **);
int /*<<< orphan*/ memcpy(unsigned char **, unsigned char **, int);
unsigned char **whine_malloc(int);
int expand_workspace(unsigned char ***wkspc, int *szp, int new) {
  unsigned char **p;
  int old = *szp;
  if (old >= new + 1)
    return 1;
  if (new >= 100)
    return 0;
  new += 5;
  if (!(p = whine_malloc(new * sizeof(unsigned char **))))
    return 0;
  if (old != 0 && *wkspc) {
    memcpy(p, *wkspc, old * sizeof(unsigned char **));
    free(*wkspc);
  }
  *wkspc = p;
  *szp = new;
  return 1;
}


x86 assembly (clang, -O0):
<expand_workspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jl     1169 <expand_workspace+0x39>
movl   $0x1,-0x4(%rbp)
jmp    120a <expand_workspace+0xda>
cmpl   $0x64,-0x1c(%rbp)
jl     117f <expand_workspace+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    120a <expand_workspace+0xda>
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <whine_malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b1 <expand_workspace+0x81>
movl   $0x0,-0x4(%rbp)
jmp    120a <expand_workspace+0xda>
cmpl   $0x0,-0x2c(%rbp)
je     11ef <expand_workspace+0xbf>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ef <expand_workspace+0xbf>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_workspace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%r13d
mov    $0x1,%ebp
cmp    %edx,%r13d
jg     119d <expand_workspace+0x6d>
mov    %edx,%ebx
xor    %ebp,%ebp
cmp    $0x63,%edx
jg     119d <expand_workspace+0x6d>
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x28(,%rbx,8),%edi
call   1050 <whine_malloc@plt>
test   %rax,%rax
je     119d <expand_workspace+0x6d>
mov    %rax,%r12
add    $0x5,%ebx
test   %r13d,%r13d
je     1192 <expand_workspace+0x62>
mov    (%r15),%rsi
test   %rsi,%rsi
je     1192 <expand_workspace+0x62>
shl    $0x3,%r13d
mov    %r12,%rdi
mov    %r13d,%edx
call   1040 <memcpy@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %r12,(%r15)
mov    %ebx,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @expand_workspace(i8*** %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
store i8*** %0, i8**** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %6
%11 = load i32, i32* %10
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
%15 = icmp sge i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 1, i32* %4
br label %55
17: ; preds = %3
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 100
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %4
br label %55
21: ; preds = %17
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 5
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = trunc i64 %26 to i32
%28 = call i8** @whine_malloc(i32 %27)
store i8** %28, i8*** %8
%29 = icmp ne i8** %28, null
br i1 %29, label %31, label %30
30: ; preds = %21
store i32 0, i32* %4
br label %55
31: ; preds = %21
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = load i8***, i8**** %5
%36 = load i8**, i8*** %35
%37 = icmp ne i8** %36, null
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = load i8**, i8*** %8
%40 = load i8***, i8**** %5
%41 = load i8**, i8*** %40
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 8
%45 = trunc i64 %44 to i32
%46 = call i32 @memcpy(i8** %39, i8** %41, i32 %45)
%47 = load i8***, i8**** %5
%48 = load i8**, i8*** %47
%49 = call i32 @free(i8** %48)
br label %50
50: ; preds = %38, %34, %31
%51 = load i8**, i8*** %8
%52 = load i8***, i8**** %5
store i8** %51, i8*** %52
%53 = load i32, i32* %7
%54 = load i32*, i32** %6
store i32 %53, i32* %54
store i32 1, i32* %4
br label %55
55: ; preds = %50, %30, %20, %16
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
define i32 @expand_workspace(i8*** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, %2
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = icmp sgt i32 %2, 99
br i1 %7, label %24, label %8
8: ; preds = %6
%9 = add nsw i32 %2, 5
%10 = shl i32 %9, 3
%11 = tail call i8** @whine_malloc(i32 %10)
%12 = icmp eq i8** %11, null
br i1 %12, label %24, label %13
13: ; preds = %8
%14 = icmp eq i32 %4, 0
br i1 %14, label %23, label %15
15: ; preds = %13
%16 = load i8**, i8*** %0
%17 = icmp eq i8** %16, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = shl i32 %4, 3
%20 = tail call i32 @memcpy(i8** %11, i8** %16, i32 %19)
%21 = load i8**, i8*** %0
%22 = tail call i32 @free(i8** %21)
br label %23
23: ; preds = %18, %15, %13
store i8** %11, i8*** %0
store i32 %9, i32* %1
br label %24
24: ; preds = %8, %6, %3, %23
%25 = phi i32 [ 1, %23 ], [ 1, %3 ], [ 0, %6 ], [ 0, %8 ]
ret i32 %25
}