#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 *realloc(void *, size_t);
int _increase_tknsize(size_t len, void **p, size_t *nlen) {
  int rc = 0;
  do {
    void *tp = NULL;
    size_t tlen = (len / (4 * 1024) + 1) * (4 * 1024);
    if (!(tp = realloc(*p, tlen))) {
      rc = 1;
      break;
    }
    *p = tp;
    *nlen = tlen;
  } while (0);
  return rc;
}


x86 assembly (clang, -O0):
<_increase_tknsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xc,%rax
add    $0x1,%rax
shl    $0xc,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1171 <_increase_tknsize+0x61>
movl   $0x1,-0x1c(%rbp)
jmp    1187 <_increase_tknsize+0x77>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_increase_tknsize>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
add    $0x1000,%rbx
and    $0xfffffffffffff000,%rbx
mov    (%rsi),%rdi
mov    %rbx,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     1146 <_increase_tknsize+0x36>
mov    %rax,(%r15)
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    114b <_increase_tknsize+0x3b>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @_increase_tknsize(i64 %0, i8** %1, i64* %2) {
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i64 %0, i64* %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
store i32 0, i32* %7
br label %10
10: ; preds = %3
store i8* null, i8** %8
%11 = load i64, i64* %4
%12 = udiv i64 %11, 4096
%13 = add i64 %12, 1
%14 = mul i64 %13, 4096
store i64 %14, i64* %9
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = load i64, i64* %9
%18 = call i8* @realloc(i8* %16, i64 %17)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %10
store i32 1, i32* %7
br label %26
21: ; preds = %10
%22 = load i8*, i8** %8
%23 = load i8**, i8*** %5
store i8* %22, i8** %23
%24 = load i64, i64* %9
%25 = load i64*, i64** %6
store i64 %24, i64* %25
br label %26
26: ; preds = %21, %20
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @_increase_tknsize(i64 %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = add i64 %0, 4096
%5 = and i64 %4, -4096
%6 = load i8*, i8** %1
%7 = tail call i8* @realloc(i8* %6, i64 %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %3
store i8* %7, i8** %1
store i64 %5, i64* %2
br label %10
10: ; preds = %3, %9
%11 = phi i32 [ 0, %9 ], [ 1, %3 ]
ret i32 %11
}