#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 */
unsigned char *intobyte(int, unsigned char, unsigned char *);
unsigned char *unpackline(unsigned char *in, unsigned char *out, int len,
                          int size, int dir) {
  unsigned char *out0 = out++;
  intobyte(0, 0, 0);
  while (len) {
    out = intobyte(size, *in, out);
    in += dir;
    --len;
  }
  out = intobyte(8, 0, out);
  *out0 = out - out0;
  return out;
}


x86 assembly (clang, -O0):
<unpackline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,-0x28(%rbp)
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
mov    %esi,%edi
call   1030 <intobyte@plt>
cmpl   $0x0,-0x14(%rbp)
je     118c <unpackline+0x7c>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rdx
movzbl %al,%esi
call   1030 <intobyte@plt>
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114a <unpackline+0x3a>
mov    -0x10(%rbp),%rdx
mov    $0x8,%edi
xor    %esi,%esi
call   1030 <intobyte@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpackline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x1(%rsi),%r12
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <intobyte@plt>
test   %ebp,%ebp
je     1159 <unpackline+0x49>
movslq %r13d,%r13
nop
movzbl (%rbx),%esi
mov    %r15d,%edi
mov    %r12,%rdx
call   1030 <intobyte@plt>
mov    %rax,%r12
add    %r13,%rbx
add    $0xffffffff,%ebp
jne    1140 <unpackline+0x30>
mov    $0x8,%edi
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <intobyte@plt>
mov    %eax,%ecx
sub    %r14d,%ecx
mov    %cl,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @unpackline(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i8*, i8** %7
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %7
store i8* %12, i8** %11
%14 = call i8* @intobyte(i32 0, i8 zeroext 0, i8* null)
br label %15
15: ; preds = %18, %5
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %15
%19 = load i32, i32* %9
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = load i8*, i8** %7
%23 = call i8* @intobyte(i32 %19, i8 zeroext %21, i8* %22)
store i8* %23, i8** %7
%24 = load i32, i32* %10
%25 = load i8*, i8** %6
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %6
%28 = load i32, i32* %8
%29 = add nsw i32 %28, -1
store i32 %29, i32* %8
br label %15
30: ; preds = %15
%31 = load i8*, i8** %7
%32 = call i8* @intobyte(i32 8, i8 zeroext 0, i8* %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i8*, i8** %11
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i8
%39 = load i8*, i8** %11
store i8 %38, i8* %39
%40 = load i8*, i8** %7
ret i8* %40
}

LLVM IR (-O2):
define i8* @unpackline(i8* nocapture %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = tail call i8* @intobyte(i32 0, i8 zeroext 0, i8* null)
%8 = icmp eq i32 %2, 0
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = sext i32 %4 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i8* [ %0, %9 ], [ %17, %11 ]
%13 = phi i8* [ %6, %9 ], [ %16, %11 ]
%14 = phi i32 [ %2, %9 ], [ %18, %11 ]
%15 = load i8, i8* %12
%16 = tail call i8* @intobyte(i32 %3, i8 zeroext %15, i8* %13)
%17 = getelementptr inbounds i8, i8* %12, i64 %10
%18 = add nsw i32 %14, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %11
20: ; preds = %11, %5
%21 = phi i8* [ %6, %5 ], [ %16, %11 ]
%22 = tail call i8* @intobyte(i32 8, i8 zeroext 0, i8* %21)
%23 = ptrtoint i8* %22 to i64
%24 = ptrtoint i8* %1 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i8
store i8 %26, i8* %1
ret i8* %22
}