#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 big2littleEndian(int);
unsigned char *bin2str(unsigned char *, char *);
unsigned char *unpack(unsigned char *buffer, char *val_out) {
  int *size = (int *)(buffer);
  *size = big2littleEndian(*size);
  buffer += 4;
  for (int t = 0; t < *size; t++) {
    buffer = bin2str(buffer, val_out);
    val_out++;
    val_out++;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<unpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <big2littleEndian@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11a4 <unpack+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <bin2str@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <unpack+0x3e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%edi
call   1030 <big2littleEndian@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
lea    0x4(%r14),%rax
test   %ecx,%ecx
jle    1157 <unpack+0x37>
xor    %ebp,%ebp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <bin2str@plt>
add    $0x2,%rbx
add    $0x1,%ebp
cmp    (%r14),%ebp
jl     1140 <unpack+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @unpack(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = bitcast i8* %7 to i32*
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = call i32 @big2littleEndian(i32 %10)
%12 = load i32*, i32** %5
store i32 %11, i32* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 4
store i8* %14, i8** %3
store i32 0, i32* %6
br label %15
15: ; preds = %28, %2
%16 = load i32, i32* %6
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = load i8*, i8** %4
%23 = call i8* @bin2str(i8* %21, i8* %22)
store i8* %23, i8** %3
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %28
28: ; preds = %20
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %15
31: ; preds = %15
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @unpack(i8* %0, i8* %1) {
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = tail call i32 @big2littleEndian(i32 %4)
store i32 %5, i32* %3
%6 = getelementptr inbounds i8, i8* %0, i64 4
%7 = icmp sgt i32 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %10, %2
%9 = phi i8* [ %6, %2 ], [ %14, %10 ]
ret i8* %9
10: ; preds = %2, %10
%11 = phi i32 [ %16, %10 ], [ 0, %2 ]
%12 = phi i8* [ %14, %10 ], [ %6, %2 ]
%13 = phi i8* [ %15, %10 ], [ %1, %2 ]
%14 = tail call i8* @bin2str(i8* %12, i8* %13)
%15 = getelementptr inbounds i8, i8* %13, i64 2
%16 = add nuw nsw i32 %11, 1
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %10, label %8
}