#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
int PMAPPROG;
int PMAPVERS;
scalar_t__ htonl(int);
int /*<<< orphan*/ memcpy(void *, scalar_t__ *, unsigned int);
int build_ping_message(void *buffer, size_t size) {
  uint32_t raw_msg[64];
  unsigned int len = 0;
  raw_msg[len++] = 0;
  raw_msg[len++] = 0;
  raw_msg[len++] = htonl(2);
  raw_msg[len++] = htonl(PMAPPROG);
  raw_msg[len++] = htonl(PMAPVERS);
  raw_msg[len++] = 0;
  raw_msg[len++] = 0;
  raw_msg[len++] = 0;
  raw_msg[len++] = 0;
  raw_msg[len++] = 0;
  len *= 4;
  if (len > size)
    return -1;
  memcpy(buffer, raw_msg, len);
  return len;
}


x86 assembly (clang, -O0):
<build_ping_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x224(%rbp)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    $0x2,%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x224(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x224(%rbp)
mov    %eax,%eax
mov    %rcx,-0x220(%rbp,%rax,8)
ff
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x224(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x224(%rbp)
mov    %eax,%eax
mov    %rcx,-0x220(%rbp,%rax,8)
ff
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %rax,%rcx
mov    -0x224(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x224(%rbp)
mov    %eax,%eax
mov    %rcx,-0x220(%rbp,%rax,8)
ff
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x224(%rbp)
mov    %eax,%eax
movq   $0x0,-0x220(%rbp,%rax,8)
mov    -0x224(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
cmp    -0x18(%rbp),%rax
jbe    12c1 <build_ping_message+0x1a1>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <build_ping_message+0x1c0>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    -0x224(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x224(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_ping_message>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    $0x2,%edi
call   1030 <htonl@plt>
mov    %rax,0x10(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %rax,0x18(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1030 <htonl@plt>
mov    %rax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movups %xmm0,0x38(%rsp)
movq   $0x0,0x48(%rsp)
mov    $0xffffffff,%ebp
cmp    $0x28,%rbx
jb     11a3 <build_ping_message+0x83>
mov    %rsp,%rsi
mov    $0x28,%ebp
mov    %r14,%rdi
mov    $0x28,%edx
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PMAPPROG = global i32 0
@PMAPVERS = global i32 0
define i32 @build_ping_message(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [64 x i64]
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 0, i32* %7
%8 = load i32, i32* %7
%9 = add i32 %8, 1
store i32 %9, i32* %7
%10 = zext i32 %8 to i64
%11 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %10
store i64 0, i64* %11
%12 = load i32, i32* %7
%13 = add i32 %12, 1
store i32 %13, i32* %7
%14 = zext i32 %12 to i64
%15 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %14
store i64 0, i64* %15
%16 = call i64 @htonl(i32 2)
%17 = load i32, i32* %7
%18 = add i32 %17, 1
store i32 %18, i32* %7
%19 = zext i32 %17 to i64
%20 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %19
store i64 %16, i64* %20
%21 = load i32, i32* @PMAPPROG
%22 = call i64 @htonl(i32 %21)
%23 = load i32, i32* %7
%24 = add i32 %23, 1
store i32 %24, i32* %7
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %25
store i64 %22, i64* %26
%27 = load i32, i32* @PMAPVERS
%28 = call i64 @htonl(i32 %27)
%29 = load i32, i32* %7
%30 = add i32 %29, 1
store i32 %30, i32* %7
%31 = zext i32 %29 to i64
%32 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %31
store i64 %28, i64* %32
%33 = load i32, i32* %7
%34 = add i32 %33, 1
store i32 %34, i32* %7
%35 = zext i32 %33 to i64
%36 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %35
store i64 0, i64* %36
%37 = load i32, i32* %7
%38 = add i32 %37, 1
store i32 %38, i32* %7
%39 = zext i32 %37 to i64
%40 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %39
store i64 0, i64* %40
%41 = load i32, i32* %7
%42 = add i32 %41, 1
store i32 %42, i32* %7
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %43
store i64 0, i64* %44
%45 = load i32, i32* %7
%46 = add i32 %45, 1
store i32 %46, i32* %7
%47 = zext i32 %45 to i64
%48 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %47
store i64 0, i64* %48
%49 = load i32, i32* %7
%50 = add i32 %49, 1
store i32 %50, i32* %7
%51 = zext i32 %49 to i64
%52 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 %51
store i64 0, i64* %52
%53 = load i32, i32* %7
%54 = mul i32 %53, 4
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = zext i32 %55 to i64
%57 = load i64, i64* %5
%58 = icmp ugt i64 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %2
store i32 -1, i32* %3
br label %66
60: ; preds = %2
%61 = load i8*, i8** %4
%62 = getelementptr inbounds [64 x i64], [64 x i64]* %6, i64 0, i64 0
%63 = load i32, i32* %7
%64 = call i32 @memcpy(i8* %61, i64* %62, i32 %63)
%65 = load i32, i32* %7
store i32 %65, i32* %3
br label %66
66: ; preds = %60, %59
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@PMAPPROG = global i32 0
@PMAPVERS = global i32 0
define i32 @build_ping_message(i8* %0, i64 %1) {
%3 = alloca [64 x i64]
%4 = bitcast [64 x i64]* %3 to i8*
%5 = bitcast [64 x i64]* %3 to i8*
%6 = tail call i64 @htonl(i32 2)
%7 = getelementptr inbounds [64 x i64], [64 x i64]* %3, i64 0, i64 2
store i64 %6, i64* %7
%8 = load i32, i32* @PMAPPROG
%9 = tail call i64 @htonl(i32 %8)
%10 = getelementptr inbounds [64 x i64], [64 x i64]* %3, i64 0, i64 3
store i64 %9, i64* %10
%11 = load i32, i32* @PMAPVERS
%12 = tail call i64 @htonl(i32 %11)
%13 = getelementptr inbounds [64 x i64], [64 x i64]* %3, i64 0, i64 4
store i64 %12, i64* %13
%14 = getelementptr inbounds [64 x i64], [64 x i64]* %3, i64 0, i64 5
%15 = icmp ult i64 %1, 40
%16 = bitcast i64* %14 to i8*
br i1 %15, label %20, label %17
17: ; preds = %2
%18 = getelementptr inbounds [64 x i64], [64 x i64]* %3, i64 0, i64 0
%19 = call i32 @memcpy(i8* %0, i64* %18, i32 40)
br label %20
20: ; preds = %2, %17
%21 = phi i32 [ 40, %17 ], [ -1, %2 ]
ret i32 %21
}