#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ myrealloc(void *, int, char *);
int /*<<< orphan*/ stderr;
int resize(void **pnt, int n, int *len, int size) {
  if (((n == *len))) {
    int dummylen = (*len) == 0 ? 2 : (*len) * 2;
    void *dummypnt = (void *)myrealloc(*pnt, dummylen * size, "resize()");
    if (!dummypnt) {
      fprintf(stderr,
              "resize::realloct: Cannot (re-)allocate %d bytes of memory\n",
              dummylen * size);
      return -1;
    }
    *len = dummylen;
    *pnt = dummypnt;
  } else if (((n > *len || n < 0 || *len < 0))) {
    fprintf(
        stderr,
        "resize: fatal memory corruption problem: n > len || n<0 || len<0!\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jne    11ed <resize+0xbd>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    116f <resize+0x3f>
mov    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    117b <resize+0x4b>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%esi
imul   -0x24(%rbp),%esi
lea    0xe6a(%rip),%rdx
call   1040 <myrealloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d4 <resize+0xa4>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
imul   -0x24(%rbp),%edx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <resize+0x110>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1239 <resize+0x109>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jg     1213 <resize+0xe3>
cmpl   $0x0,-0x14(%rbp)
jl     1213 <resize+0xe3>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1234 <resize+0x104>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1239 <resize+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    (%rdx),%ecx
cmp    %esi,%ecx
jne    1175 <resize+0x45>
mov    %rdx,%r14
mov    %rdi,%r15
lea    (%rsi,%rsi,1),%eax
test   %esi,%esi
mov    $0x2,%ebp
cmovne %eax,%ebp
mov    (%rdi),%rdi
imul   %ebp,%ebx
lea    0xea1(%rip),%rdx
mov    %ebx,%esi
call   1040 <myrealloc@plt>
test   %rax,%rax
je     119e <resize+0x6e>
mov    %ebp,(%r14)
mov    %rax,(%r15)
xor    %eax,%eax
jmp    11bc <resize+0x8c>
jl     117d <resize+0x4d>
xor    %eax,%eax
or     %esi,%ecx
jns    11bc <resize+0x8c>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"resize()\00"
@stderr = global i32 0
@.str.1 = [59 x i8] c"resize::realloct: Cannot (re-)allocate %d bytes of memory\0A\00"
@.str.2 = [67 x i8] c"resize: fatal memory corruption problem: n > len || n<0 || len<0!\0A\00"
define i32 @resize(i8** %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%12 = load i32, i32* %7
%13 = load i32*, i32** %8
%14 = load i32, i32* %13
%15 = icmp eq i32 %12, %14
br i1 %15, label %16, label %47
16: ; preds = %4
%17 = load i32*, i32** %8
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %25
21: ; preds = %16
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 2
br label %25
25: ; preds = %21, %20
%26 = phi i32 [ 2, %20 ], [ %24, %21 ]
store i32 %26, i32* %10
%27 = load i8**, i8*** %6
%28 = load i8*, i8** %27
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = mul nsw i32 %29, %30
%32 = call i64 @myrealloc(i8* %28, i32 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = icmp ne i8* %34, null
br i1 %35, label %42, label %36
36: ; preds = %25
%37 = load i32, i32* @stderr
%38 = load i32, i32* %10
%39 = load i32, i32* %9
%40 = mul nsw i32 %38, %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 -1, i32* %5
br label %65
42: ; preds = %25
%43 = load i32, i32* %10
%44 = load i32*, i32** %8
store i32 %43, i32* %44
%45 = load i8*, i8** %11
%46 = load i8**, i8*** %6
store i8* %45, i8** %46
br label %64
47: ; preds = %4
%48 = load i32, i32* %7
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = icmp sgt i32 %48, %50
br i1 %51, label %59, label %52
52: ; preds = %47
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %59, label %55
55: ; preds = %52
%56 = load i32*, i32** %8
%57 = load i32, i32* %56
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55, %52, %47
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %55
br label %64
64: ; preds = %63, %42
store i32 0, i32* %5
br label %65
65: ; preds = %64, %36
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"resize()\00"
@stderr = global i32 0
@.str.1 = [59 x i8] c"resize::realloct: Cannot (re-)allocate %d bytes of memory\0A\00"
@.str.2 = [67 x i8] c"resize: fatal memory corruption problem: n > len || n<0 || len<0!\0A\00"
define i32 @resize(i8** nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, %1
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = icmp eq i32 %1, 0
%9 = shl nsw i32 %1, 1
%10 = select i1 %8, i32 2, i32 %9
%11 = load i8*, i8** %0
%12 = mul nsw i32 %10, %3
%13 = tail call i64 @myrealloc(i8* %11, i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %7
%16 = inttoptr i64 %13 to i8*
store i32 %10, i32* %2
store i8* %16, i8** %0
br label %29
17: ; preds = %7
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %29
20: ; preds = %4
%21 = icmp slt i32 %5, %1
%22 = or i32 %5, %1
%23 = icmp slt i32 %22, 0
%24 = or i1 %21, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %20, %15, %17
%30 = phi i32 [ -1, %17 ], [ 0, %15 ], [ 0, %20 ]
ret i32 %30
}