#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 */
scalar_t__ emit(char const *, size_t, void *(*)(void *, char const *, size_t),
                void **);
int pad(const char *s, size_t n, void *(*cons)(void *, const char *, size_t),
        void **parg) {
  while (n > 0) {
    size_t j = (((16)) < (n) ? ((16)) : (n));
    if (emit(s, j, cons, parg) < 0)
      return (-1);
    n -= j;
  }
  return 0;
}


x86 assembly (clang, -O0):
<pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    119f <pad+0x8f>
mov    $0x10,%eax
cmp    -0x18(%rbp),%rax
jae    1150 <pad+0x40>
mov    $0x10,%eax
mov    %rax,-0x38(%rbp)
jmp    1158 <pad+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1030 <emit@plt>
cmp    $0x0,%rax
jge    118b <pad+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <pad+0x96>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <pad+0x18>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
cs nopw 0x0(%rax,%rax,1)
nop
test   %rbx,%rbx
je     1163 <pad+0x53>
cmp    $0x10,%rbx
mov    $0x10,%r13d
cmovb  %rbx,%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <emit@plt>
sub    %r13,%rbx
test   %rax,%rax
jns    1130 <pad+0x20>
mov    $0xffffffff,%eax
jmp    1165 <pad+0x55>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @pad(i8* %0, i64 %1, i8* (i8*, i8*, i64)* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8* (i8*, i8*, i64)*
%9 = alloca i8**
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* (i8*, i8*, i64)* %2, i8* (i8*, i8*, i64)** %8
store i8** %3, i8*** %9
br label %11
11: ; preds = %29, %4
%12 = load i64, i64* %7
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i64, i64* %7
%16 = icmp ult i64 16, %15
br i1 %16, label %17, label %18
17: ; preds = %14
br label %20
18: ; preds = %14
%19 = load i64, i64* %7
br label %20
20: ; preds = %18, %17
%21 = phi i64 [ 16, %17 ], [ %19, %18 ]
store i64 %21, i64* %10
%22 = load i8*, i8** %6
%23 = load i64, i64* %10
%24 = load i8* (i8*, i8*, i64)*, i8* (i8*, i8*, i64)** %8
%25 = load i8**, i8*** %9
%26 = call i64 @emit(i8* %22, i64 %23, i8* (i8*, i8*, i64)* %24, i8** %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %20
store i32 -1, i32* %5
br label %34
29: ; preds = %20
%30 = load i64, i64* %10
%31 = load i64, i64* %7
%32 = sub i64 %31, %30
store i64 %32, i64* %7
br label %11
33: ; preds = %11
store i32 0, i32* %5
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @pad(i8* %0, i64 %1, i8* (i8*, i8*, i64)* %2, i8** %3) {
br label %5
5: ; preds = %8, %4
%6 = phi i64 [ %1, %4 ], [ %13, %8 ]
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = icmp ult i64 %6, 16
%10 = select i1 %9, i64 %6, i64 16
%11 = tail call i64 @emit(i8* %0, i64 %10, i8* (i8*, i8*, i64)* %2, i8** %3)
%12 = icmp sgt i64 %11, -1
%13 = sub i64 %6, %10
br i1 %12, label %5, label %14
14: ; preds = %8, %5
%15 = phi i32 [ -1, %8 ], [ 0, %5 ]
ret i32 %15
}