int undflt(unsigned char *in, int insz, unsigned char *out, int outsz) {
  typedef struct {
    void *input;
    void *input_end;
    int dummy1;
    int dummy2;
    void *ptr;
    void *output;
    void *output_end;
    char data[0x17c8];
  } undflt_ctx_t;
  undflt_ctx_t *ctx;
  int ret;
  undflt_init();
  ctx = calloc(sizeof(undflt_ctx_t), 1);
  if (!ctx)
    return (-1);
  ctx->input = in;
  ctx->input_end = in + insz;
  ctx->ptr = out;
  ctx->output = out;
  ctx->output_end = out + outsz;
  ret = undflt_func(ctx);
  free(ctx);
  if (!ret)
    return (-1);
  return (outsz);
}


x86 assembly (clang, -O0):
<undflt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    $0x0,%al
call   1050 <undflt_init@plt>
mov    $0x17f8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1187 <undflt+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <undflt+0xc3>
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rax
add    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1040 <undflt_func@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x34(%rbp)
jne    11fd <undflt+0xbd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <undflt+0xc3>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<undflt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <undflt_init@plt>
mov    $0x17f8,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11b0 <undflt+0x70>
mov    %rax,%rbx
mov    %rbp,(%rax)
movslq %r12d,%rax
add    %rbp,%rax
mov    %rax,0x8(%rbx)
mov    %r14,0x18(%rbx)
mov    %r14,0x20(%rbx)
movslq %r15d,%rbp
add    %rbp,%r14
mov    %r14,0x28(%rbx)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <undflt_func@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
cmp    $0x1,%r14d
sbb    %eax,%eax
or     %eax,%ebp
jmp    11b5 <undflt+0x75>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.undflt_ctx_t = type { i8*, i8*, i32, i32, i8*, i8*, i8*, [6088 x i8] }
define i32 @undflt(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %struct.undflt_ctx_t*
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = call i32 (...) @undflt_init()
%13 = call i8* @calloc(i64 6136, i64 1)
%14 = bitcast i8* %13 to %struct.undflt_ctx_t*
store %struct.undflt_ctx_t* %14, %struct.undflt_ctx_t** %10
%15 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%16 = icmp ne %struct.undflt_ctx_t* %15, null
br i1 %16, label %18, label %17
17: ; preds = %4
store i32 -1, i32* %5
br label %49
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%21 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%27 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %26, i32 0, i32 1
store i8* %25, i8** %27
%28 = load i8*, i8** %8
%29 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%30 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %29, i32 0, i32 4
store i8* %28, i8** %30
%31 = load i8*, i8** %8
%32 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%33 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %32, i32 0, i32 5
store i8* %31, i8** %33
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%39 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %38, i32 0, i32 6
store i8* %37, i8** %39
%40 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%41 = call i32 (%struct.undflt_ctx_t*, ...) bitcast (i32 (...)* @undflt_func to i32 (%struct.undflt_ctx_t*, ...)*)(%struct.undflt_ctx_t* %40)
store i32 %41, i32* %11
%42 = load %struct.undflt_ctx_t*, %struct.undflt_ctx_t** %10
%43 = bitcast %struct.undflt_ctx_t* %42 to i8*
%44 = load i32, i32* %11
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %18
store i32 -1, i32* %5
br label %49
47: ; preds = %18
%48 = load i32, i32* %9
store i32 %48, i32* %5
br label %49
49: ; preds = %47, %46, %17
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
%struct.undflt_ctx_t = type { i8*, i8*, i32, i32, i8*, i8*, i8*, [6088 x i8] }
define i32 @undflt(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 (...) @undflt_init()
%6 = tail call dereferenceable_or_null(6136) i8* @calloc(i64 6136, i64 1)
%7 = bitcast i8* %6 to %struct.undflt_ctx_t*
%8 = icmp eq i8* %6, null
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %7, i64 0, i32 0
store i8* %0, i8** %10
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %7, i64 0, i32 1
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %7, i64 0, i32 4
store i8* %2, i8** %14
%15 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %7, i64 0, i32 5
store i8* %2, i8** %15
%16 = sext i32 %3 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = getelementptr inbounds %struct.undflt_ctx_t, %struct.undflt_ctx_t* %7, i64 0, i32 6
store i8* %17, i8** %18
%19 = tail call i32 (%struct.undflt_ctx_t*, ...) bitcast (i32 (...)* @undflt_func to i32 (%struct.undflt_ctx_t*, ...)*)(%struct.undflt_ctx_t* %7)
tail call void @free(i8* %6)
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i32 -1, i32 %3
br label %22
22: ; preds = %9, %4
%23 = phi i32 [ -1, %4 ], [ %21, %9 ]
ret i32 %23
}