#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 */
void *calloc(int, int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ memcpy(void *, void *, int);
int CompSystem_SetArraySize(void **array, int elementSize, int size,
                            int newSize) {
  int minSize;
  void *temp;
  temp = calloc(newSize, elementSize);
  minSize = (((size) < (newSize)) ? (size) : (newSize));
  memcpy(temp, (*array), minSize * elementSize);
  free(*array);
  (*array) = temp;
  return newSize;
}


x86 assembly (clang, -O0):
<CompSystem_SetArraySize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116b <CompSystem_SetArraySize+0x3b>
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1171 <CompSystem_SetArraySize+0x41>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%edx
imul   -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompSystem_SetArraySize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %ecx,%edi
call   1040 <calloc@plt>
mov    %rax,%r12
cmp    %ebx,%ebp
cmovge %ebx,%ebp
mov    (%r15),%rsi
imul   %r14d,%ebp
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %r12,(%r15)
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @CompSystem_SetArraySize(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = call i8* @calloc(i32 %11, i32 %12)
store i8* %13, i8** %10
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %7
br label %21
19: ; preds = %4
%20 = load i32, i32* %8
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
store i32 %22, i32* %9
%23 = load i8*, i8** %10
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = mul nsw i32 %26, %27
%29 = call i32 @memcpy(i8* %23, i8* %25, i32 %28)
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %10
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
%35 = load i32, i32* %8
ret i32 %35
}

LLVM IR (-O2):
define i32 @CompSystem_SetArraySize(i8** nocapture %0, i32 %1, i32 %2, i32 returned %3) {
%5 = tail call i8* @calloc(i32 %3, i32 %1)
%6 = icmp slt i32 %2, %3
%7 = select i1 %6, i32 %2, i32 %3
%8 = load i8*, i8** %0
%9 = mul nsw i32 %7, %1
%10 = tail call i32 @memcpy(i8* %5, i8* %8, i32 %9)
%11 = load i8*, i8** %0
%12 = tail call i32 @free(i8* %11)
store i8* %5, i8** %0
ret i32 %3
}