#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*/ ft_memdel(void **);
scalar_t__ malloc(int);
int /*<<< orphan*/ show_alloc_mem();
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int test_max(void) {
  char **ptr;
  int i;
  int len;
  int min = 1;
  int max = 600;
  if (!(ptr = (char **)malloc(max * sizeof(char **)))) {
    exit(185);
  }
  show_alloc_mem();
  i = min;
  while (i < max) {
    len = i;
    if (!(ptr[i] = (char *)malloc(len))) {
      exit(197);
    }
    snprintf(ptr[i], len, "%0*d", len, 1);
    show_alloc_mem();
    ++i;
  }
  i = min;
  while (i < max) {
    ft_memdel((void **)&ptr[i++]);
  }
  show_alloc_mem();
  ft_memdel((void **)&ptr);
  show_alloc_mem();
  return (0);
}


x86 assembly (clang, -O0):
<test_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x14(%rbp)
movl   $0x258,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    118d <test_max+0x3d>
mov    $0xb9,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1040 <show_alloc_mem@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    120d <test_max+0xbd>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    11d4 <test_max+0x84>
mov    $0xc5,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%esi
mov    -0x10(%rbp),%ecx
lea    0xe13(%rip),%rdx
mov    $0x1,%r8d
call   1050 <snprintf@plt>
mov    $0x0,%al
call   1040 <show_alloc_mem@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119a <test_max+0x4a>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1241 <test_max+0xf1>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cltq
shl    $0x3,%rax
add    %rax,%rdi
call   1030 <ft_memdel@plt>
jmp    1213 <test_max+0xc3>
mov    $0x0,%al
call   1040 <show_alloc_mem@plt>
lea    -0x8(%rbp),%rdi
call   1030 <ft_memdel@plt>
mov    $0x0,%al
call   1040 <show_alloc_mem@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_max>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x12c0,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1224 <test_max+0xd4>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <show_alloc_mem@plt>
mov    $0x1,%ebx
lea    0xe79(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     121a <test_max+0xca>
mov    0x8(%rsp),%r14
mov    (%r14,%rbx,8),%rdi
mov    %ebx,%esi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    $0x1,%r8d
call   1050 <snprintf@plt>
xor    %eax,%eax
call   1040 <show_alloc_mem@plt>
add    $0x1,%rbx
cmp    $0x258,%rbx
jne    1190 <test_max+0x40>
mov    $0x8,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r14,%rbx,1),%rdi
call   1030 <ft_memdel@plt>
add    $0x8,%rbx
cmp    $0x12c0,%rbx
jne    11e0 <test_max+0x90>
xor    %eax,%eax
call   1040 <show_alloc_mem@plt>
lea    0x8(%rsp),%rdi
call   1030 <ft_memdel@plt>
xor    %eax,%eax
call   1040 <show_alloc_mem@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0xc5,%edi
call   1070 <exit@plt>
mov    $0xb9,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%0*d\00"
define i32 @test_max() {
%1 = alloca i8**
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 1, i32* %4
store i32 600, i32* %5
%6 = load i32, i32* %5
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8**
store i8** %11, i8*** %1
%12 = icmp ne i8** %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @exit(i32 185)
unreachable
15: ; preds = %0
%16 = call i32 (...) @show_alloc_mem()
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %18
18: ; preds = %34, %15
%19 = load i32, i32* %2
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %46
22: ; preds = %18
%23 = load i32, i32* %2
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
%27 = load i8**, i8*** %1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
store i8* %26, i8** %30
%31 = icmp ne i8* %26, null
br i1 %31, label %34, label %32
32: ; preds = %22
%33 = call i32 @exit(i32 197)
unreachable
34: ; preds = %22
%35 = load i8**, i8*** %1
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* %3
%41 = load i32, i32* %3
%42 = call i32 @snprintf(i8* %39, i32 %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %41, i32 1)
%43 = call i32 (...) @show_alloc_mem()
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %18
46: ; preds = %18
%47 = load i32, i32* %4
store i32 %47, i32* %2
br label %48
48: ; preds = %52, %46
%49 = load i32, i32* %2
%50 = load i32, i32* %5
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = load i8**, i8*** %1
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8*, i8** %53, i64 %56
%58 = call i32 @ft_memdel(i8** %57)
br label %48
59: ; preds = %48
%60 = call i32 (...) @show_alloc_mem()
%61 = bitcast i8*** %1 to i8**
%62 = call i32 @ft_memdel(i8** %61)
%63 = call i32 (...) @show_alloc_mem()
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%0*d\00"
define i32 @test_max() {
%1 = alloca i8**
%2 = bitcast i8*** %1 to i8*
%3 = tail call i64 @malloc(i32 4800)
%4 = inttoptr i64 %3 to i8**
store i8** %4, i8*** %1
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @exit(i32 185)
unreachable
8: ; preds = %0
%9 = tail call i32 (...) @show_alloc_mem()
br label %10
10: ; preds = %8, %20
%11 = phi i8** [ %4, %8 ], [ %21, %20 ]
%12 = phi i64 [ 1, %8 ], [ %26, %20 ]
%13 = trunc i64 %12 to i32
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = getelementptr inbounds i8*, i8** %11, i64 %12
store i8* %15, i8** %16
%17 = icmp eq i64 %14, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = tail call i32 @exit(i32 197)
unreachable
20: ; preds = %10
%21 = load i8**, i8*** %1
%22 = getelementptr inbounds i8*, i8** %21, i64 %12
%23 = load i8*, i8** %22
%24 = tail call i32 @snprintf(i8* %23, i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13, i32 1)
%25 = tail call i32 (...) @show_alloc_mem()
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, 600
br i1 %27, label %28, label %10
28: ; preds = %20, %28
%29 = phi i64 [ %30, %28 ], [ 1, %20 ]
%30 = add nuw nsw i64 %29, 1
%31 = getelementptr inbounds i8*, i8** %21, i64 %29
%32 = tail call i32 @ft_memdel(i8** %31)
%33 = icmp eq i64 %30, 600
br i1 %33, label %34, label %28
34: ; preds = %28
%35 = tail call i32 (...) @show_alloc_mem()
%36 = bitcast i8*** %1 to i8**
%37 = call i32 @ft_memdel(i8** %36)
%38 = call i32 (...) @show_alloc_mem()
ret i32 0
}