#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 */
size_t pack(unsigned char *, char *, char, int /*<<< orphan*/, int, int, char *,
            double);
int /*<<< orphan*/ packi16(unsigned char *, size_t);
int /*<<< orphan*/ printf(char *, char, ...);
int /*<<< orphan*/ unpack(unsigned char *, char *, char *, size_t *, short *,
                          long *, char *, float *);
int main(void) {
  unsigned char buf[1024];
  char magic;
  short monkeycount;
  long altitude;
  float absurdityfactor;
  char *s = "Great unmitigated Zot!  You've found the Runestaff!";
  char s2[96];
  size_t packetsize, ps2;
  packetsize = pack(buf, "chhlsf", 'B', 0, 37, -5, s, -3490.6677);
  packi16(buf + 1, packetsize);
  printf("packet is %d bytes\n", packetsize);
  unpack(buf, "chhl96sf", &magic, &ps2, &monkeycount, &altitude, s2,
         &absurdityfactor);
  printf("'%c' %d %d %ld \"%s\" %f\n", magic, ps2, monkeycount, altitude, s2,
         absurdityfactor);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaf(%rip),%rax
mov    %rax,-0x430(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x430(%rbp),%rax
lea    0xec7(%rip),%rsi
mov    $0x42,%edx
xor    %ecx,%ecx
mov    $0x25,%r8d
mov    $0xfffffffb,%r9d
movsd  0xe70(%rip),%xmm0
mov    %rax,(%rsp)
call   1030 <pack@plt>
mov    %rax,-0x498(%rbp)
lea    -0x410(%rbp),%rdi
add    $0x1,%rdi
mov    -0x498(%rbp),%rsi
call   1060 <packi16@plt>
mov    -0x498(%rbp),%rax
lea    0xe7e(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x490(%rbp),%r10
lea    0xe73(%rip),%rsi
lea    -0x411(%rbp),%rdx
lea    -0x4a0(%rbp),%rcx
lea    -0x414(%rbp),%r8
lea    -0x420(%rbp),%r9
lea    -0x424(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <unpack@plt>
mov    -0x411(%rbp),%al
mov    -0x4a0(%rbp),%rdx
movswl -0x414(%rbp),%ecx
mov    -0x420(%rbp),%r8
lea    -0x490(%rbp),%r9
movss  -0x424(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xe16(%rip),%rdi
movsbl %al,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x488,%rsp
sub    $0x8,%rsp
lea    0xeb3(%rip),%rax
lea    0xee0(%rip),%rsi
lea    0x88(%rsp),%r14
movsd  0xe94(%rip),%xmm0
mov    %r14,%rdi
mov    $0x42,%edx
xor    %ecx,%ecx
mov    $0x25,%r8d
mov    $0xfffffffb,%r9d
push   %rax
call   1030 <pack@plt>
add    $0x10,%rsp
mov    %rax,%rbx
lea    0x81(%rsp),%rdi
mov    %rax,%rsi
call   1060 <packi16@plt>
movsbl %bl,%esi
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rax
lea    0x20(%rsp),%rbx
lea    0xe96(%rip),%rsi
lea    0x9(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xa(%rsp),%r8
lea    0x18(%rsp),%r9
mov    %r14,%rdi
push   %rax
push   %rbx
call   1050 <unpack@plt>
add    $0x10,%rsp
movsbl 0x9(%rsp),%esi
mov    0x10(%rsp),%rdx
movswl 0xa(%rsp),%ecx
mov    0x18(%rsp),%r8
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe58(%rip),%rdi
mov    %rbx,%r9
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x488,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Great unmitigated Zot! You've found the Runestaff!\00"
@.str.1 = [7 x i8] c"chhlsf\00"
@.str.2 = [20 x i8] c"packet is %d bytes\0A\00"
@.str.3 = [9 x i8] c"chhl96sf\00"
@.str.4 = [24 x i8] c"'%c' %d %d %ld \22%s\22 %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8
%4 = alloca i16
%5 = alloca i64
%6 = alloca float
%7 = alloca i8*
%8 = alloca [96 x i8]
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = load i8*, i8** %7
%13 = call i64 @pack(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 signext 66, i32 0, i32 37, i32 -5, i8* %12, double 0xC0AB4555DCC63F14)
store i64 %13, i64* %9
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i64, i64* %9
%17 = call i32 @packi16(i8* %15, i64 %16)
%18 = load i64, i64* %9
%19 = trunc i64 %18 to i8
%20 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8 signext %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [96 x i8], [96 x i8]* %8, i64 0, i64 0
%23 = call i32 @unpack(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %3, i64* %10, i16* %4, i64* %5, i8* %22, float* %6)
%24 = load i8, i8* %3
%25 = load i64, i64* %10
%26 = load i16, i16* %4
%27 = sext i16 %26 to i32
%28 = load i64, i64* %5
%29 = getelementptr inbounds [96 x i8], [96 x i8]* %8, i64 0, i64 0
%30 = load float, float* %6
%31 = fpext float %30 to double
%32 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8 signext %24, i64 %25, i32 %27, i64 %28, i8* %29, double %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [52 x i8] c"Great unmitigated Zot! You've found the Runestaff!\00"
@.str.1 = [7 x i8] c"chhlsf\00"
@.str.2 = [20 x i8] c"packet is %d bytes\0A\00"
@.str.3 = [9 x i8] c"chhl96sf\00"
@.str.4 = [24 x i8] c"'%c' %d %d %ld \22%s\22 %f\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i8
%3 = alloca i16
%4 = alloca i64
%5 = alloca float
%6 = alloca [96 x i8]
%7 = alloca i64
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%9 = bitcast i16* %3 to i8*
%10 = bitcast i64* %4 to i8*
%11 = bitcast float* %5 to i8*
%12 = getelementptr inbounds [96 x i8], [96 x i8]* %6, i64 0, i64 0
%13 = bitcast i64* %7 to i8*
%14 = call i64 @pack(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 signext 66, i32 0, i32 37, i32 -5, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), double 0xC0AB4555DCC63F14)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 1
%16 = call i32 @packi16(i8* %15, i64 %14)
%17 = trunc i64 %14 to i8
%18 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8 signext %17)
%19 = call i32 @unpack(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2, i64* %7, i16* %3, i64* %4, i8* %12, float* %5)
%20 = load i8, i8* %2
%21 = load i64, i64* %7
%22 = load i16, i16* %3
%23 = sext i16 %22 to i32
%24 = load i64, i64* %4
%25 = load float, float* %5
%26 = fpext float %25 to double
%27 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8 signext %20, i64 %21, i32 %23, i64 %24, i8* %12, double %26)
ret i32 0
}