#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*/ error_and_exit(char *, char *, int, char *);
int size_to_size_class(size_t);
void *small_malloc(int);
void *cmalloc_memalign(size_t boundary, size_t size) {
  if (size == 0)
    return NULL;
  if (boundary <= 256 && size <= (size_t)(16 * 4 * 1024)) {
    int boundary_cls = size_to_size_class(boundary);
    int size_cls = size_to_size_class(size);
    int alloc_cls = boundary_cls > size_cls ? boundary_cls : size_cls;
    return small_malloc(alloc_cls);
  } else {
    error_and_exit("CMalloc: Error at %s:%d %s.\n",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/"
                   "heads/master/sources/cmalloc.c",
                   182, "memalign() called but not fully implemented!");
    return NULL;
  }
}


x86 assembly (clang, -O0):
<cmalloc_memalign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1158 <cmalloc_memalign+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11e7 <cmalloc_memalign+0xb7>
cmpq   $0x100,-0x10(%rbp)
ja     11c0 <cmalloc_memalign+0x90>
cmpq   $0x10000,-0x18(%rbp)
ja     11c0 <cmalloc_memalign+0x90>
mov    -0x10(%rbp),%rdi
call   1030 <size_to_size_class@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <size_to_size_class@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11a3 <cmalloc_memalign+0x73>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11a9 <cmalloc_memalign+0x79>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <small_malloc@plt>
mov    %rax,-0x8(%rbp)
jmp    11e7 <cmalloc_memalign+0xb7>
lea    0xe39(%rip),%rdi
lea    0xe4f(%rip),%rsi
mov    $0xb6,%edx
lea    0xed3(%rip),%rcx
call   1040 <error_and_exit@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmalloc_memalign>:
push   %rbp
push   %rbx
push   %rax
test   %rsi,%rsi
je     118d <cmalloc_memalign+0x5d>
cmp    $0x100,%rdi
ja     116e <cmalloc_memalign+0x3e>
mov    %rsi,%rbx
cmp    $0x10000,%rsi
ja     116e <cmalloc_memalign+0x3e>
call   1030 <size_to_size_class@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <size_to_size_class@plt>
cmp    %eax,%ebp
cmovle %eax,%ebp
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <small_malloc@plt>
lea    0xe8b(%rip),%rdi
lea    0xea1(%rip),%rsi
lea    0xf2a(%rip),%rcx
mov    $0xb6,%edx
call   1040 <error_and_exit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"CMalloc: Error at %s:%d %s.\0A\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/heads/master/sources/cmalloc.c\00"
@.str.2 = [45 x i8] c"memalign() called but not fully implemented!\00"
define i8* @cmalloc_memalign(i64 %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %4
store i64 %1, i64* %5
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i8* null, i8** %3
br label %36
12: ; preds = %2
%13 = load i64, i64* %4
%14 = icmp ule i64 %13, 256
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = load i64, i64* %5
%17 = icmp ule i64 %16, 65536
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i64, i64* %4
%20 = call i32 @size_to_size_class(i64 %19)
store i32 %20, i32* %6
%21 = load i64, i64* %5
%22 = call i32 @size_to_size_class(i64 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = load i32, i32* %6
br label %30
28: ; preds = %18
%29 = load i32, i32* %7
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = call i8* @small_malloc(i32 %32)
store i8* %33, i8** %3
br label %36
34: ; preds = %15, %12
%35 = call i32 @error_and_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 182, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %3
br label %36
36: ; preds = %34, %30, %11
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@.str = [29 x i8] c"CMalloc: Error at %s:%d %s.\0A\00"
@.str.1 = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/maokelong/cmalloc/refs/heads/master/sources/cmalloc.c\00"
@.str.2 = [45 x i8] c"memalign() called but not fully implemented!\00"
define i8* @cmalloc_memalign(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = icmp ult i64 %0, 257
%6 = icmp ult i64 %1, 65537
%7 = and i1 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = tail call i32 @size_to_size_class(i64 %0)
%10 = tail call i32 @size_to_size_class(i64 %1)
%11 = icmp sgt i32 %9, %10
%12 = select i1 %11, i32 %9, i32 %10
%13 = tail call i8* @small_malloc(i32 %12)
br label %16
14: ; preds = %4
%15 = tail call i32 @error_and_exit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32 182, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %2, %14, %8
%17 = phi i8* [ %13, %8 ], [ null, %14 ], [ null, %2 ]
ret i8* %17
}