#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*/ M_MMAP_MAX;
int /*<<< orphan*/ M_TRIM_THRESHOLD;
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ mallopt(int /*<<< orphan*/, int);
void __pathscale_malloc_alg(int mode) {
  if (getenv("OPEN64_NO_MALLOC_ALG") != NULL)
    return;
  if (mode < 1)
    mode = 1;
  else if (mode > 4) {
    mode = 4;
  }
  switch (mode) {
  case 1:
    mallopt(M_MMAP_MAX, 0x2);
    mallopt(M_TRIM_THRESHOLD, 0x10000000);
    break;
  case 2:
    mallopt(M_MMAP_MAX, 0x2);
    mallopt(M_TRIM_THRESHOLD, 0x40000000);
    break;
  case 3:
    mallopt(M_MMAP_MAX, 0x0);
    mallopt(M_TRIM_THRESHOLD, 0xffffffff);
    break;
  case 4:
    mallopt(M_MMAP_MAX, 0x2);
    mallopt(M_TRIM_THRESHOLD, 0x10000000);
    break;
  }
}


x86 assembly (clang, -O0):
<__pathscale_malloc_alg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xede(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1146 <__pathscale_malloc_alg+0x26>
jmp    123f <__pathscale_malloc_alg+0x11f>
cmpl   $0x1,-0x4(%rbp)
jge    115c <__pathscale_malloc_alg+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1172 <__pathscale_malloc_alg+0x52>
cmpl   $0x4,-0x4(%rbp)
jle    116d <__pathscale_malloc_alg+0x4d>
movl   $0x4,-0x4(%rbp)
jmp    1172 <__pathscale_malloc_alg+0x52>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     123f <__pathscale_malloc_alg+0x11f>
mov    -0x10(%rbp),%rax
lea    0xe6e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1040 <mallopt@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    $0x10000000,%esi
call   1040 <mallopt@plt>
jmp    123f <__pathscale_malloc_alg+0x11f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1040 <mallopt@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    $0x40000000,%esi
call   1040 <mallopt@plt>
jmp    123f <__pathscale_malloc_alg+0x11f>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1040 <mallopt@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
call   1040 <mallopt@plt>
jmp    123f <__pathscale_malloc_alg+0x11f>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1040 <mallopt@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    $0x10000000,%esi
call   1040 <mallopt@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__pathscale_malloc_alg>:
push   %rbx
mov    %edi,%ebx
lea    0xed6(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1186 <__pathscale_malloc_alg+0x66>
cmp    $0x4,%ebx
mov    $0x4,%ecx
cmovl  %ebx,%ecx
test   %ecx,%ecx
mov    $0x1,%eax
cmovg  %ecx,%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1186 <__pathscale_malloc_alg+0x66>
cltq
lea    0xebe(%rip),%rcx
mov    (%rcx,%rax,4),%esi
lea    0xec4(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1040 <mallopt@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
pop    %rbx
jmp    1040 <mallopt@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"OPEN64_NO_MALLOC_ALG\00"
@M_MMAP_MAX = global i32 0
@M_TRIM_THRESHOLD = global i32 0
define void @__pathscale_malloc_alg(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i32* %3, null
br i1 %4, label %5, label %6
5: ; preds = %1
br label %37
6: ; preds = %1
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %6
store i32 1, i32* %2
br label %15
10: ; preds = %6
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 4
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 4, i32* %2
br label %14
14: ; preds = %13, %10
br label %15
15: ; preds = %14, %9
%16 = load i32, i32* %2
switch i32 %16, label %37 [
i32 1, label %17
i32 2, label %22
i32 3, label %27
i32 4, label %32
]
17: ; preds = %15
%18 = load i32, i32* @M_MMAP_MAX
%19 = call i32 @mallopt(i32 %18, i32 2)
%20 = load i32, i32* @M_TRIM_THRESHOLD
%21 = call i32 @mallopt(i32 %20, i32 268435456)
br label %37
22: ; preds = %15
%23 = load i32, i32* @M_MMAP_MAX
%24 = call i32 @mallopt(i32 %23, i32 2)
%25 = load i32, i32* @M_TRIM_THRESHOLD
%26 = call i32 @mallopt(i32 %25, i32 1073741824)
br label %37
27: ; preds = %15
%28 = load i32, i32* @M_MMAP_MAX
%29 = call i32 @mallopt(i32 %28, i32 0)
%30 = load i32, i32* @M_TRIM_THRESHOLD
%31 = call i32 @mallopt(i32 %30, i32 -1)
br label %37
32: ; preds = %15
%33 = load i32, i32* @M_MMAP_MAX
%34 = call i32 @mallopt(i32 %33, i32 2)
%35 = load i32, i32* @M_TRIM_THRESHOLD
%36 = call i32 @mallopt(i32 %35, i32 268435456)
br label %37
37: ; preds = %5, %15, %32, %27, %22, %17
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"OPEN64_NO_MALLOC_ALG\00"
@M_MMAP_MAX = global i32 0
@M_TRIM_THRESHOLD = global i32 0
@switch.table.__pathscale_malloc_alg = [4 x i32] [i32 2, i32 2, i32 0, i32 2]
@switch.table.__pathscale_malloc_alg.1 = [4 x i32] [i32 268435456, i32 1073741824, i32 -1, i32 268435456]
define void @__pathscale_malloc_alg(i32 %0) {
%2 = tail call i32* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = icmp slt i32 %0, 4
%6 = select i1 %5, i32 %0, i32 4
%7 = icmp sgt i32 %6, 1
%8 = select i1 %7, i32 %6, i32 1
%9 = add nsw i32 %8, -1
%10 = icmp ult i32 %9, 4
br i1 %10, label %11, label %22
11: ; preds = %4
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.__pathscale_malloc_alg, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.__pathscale_malloc_alg.1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* @M_MMAP_MAX
%19 = tail call i32 @mallopt(i32 %18, i32 %14)
%20 = load i32, i32* @M_TRIM_THRESHOLD
%21 = tail call i32 @mallopt(i32 %20, i32 %17)
br label %22
22: ; preds = %4, %11, %1
ret void
}