#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 int htonl(unsigned int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int sig_makefile(char *data, unsigned int datalen, char *sig,
                 unsigned int siglen, char *filebuf, unsigned int *filelen) {
  *(unsigned int *)filebuf = htonl(datalen);
  memcpy(filebuf + sizeof(int), data, datalen);
  *(unsigned int *)(filebuf + sizeof(int) + datalen) = htonl(siglen);
  memcpy(filebuf + sizeof(int) + datalen + sizeof(int), sig, siglen);
  *filelen = sizeof(int) + datalen + sizeof(int) + siglen;
  return 0;
}


x86 assembly (clang, -O0):
<sig_makefile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %edx,0x4(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0xc(%rbp),%eax
add    %rax,%rdi
add    $0x4,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x4,%rax
add    $0x4,%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_makefile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %rdx,%r13
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %esi,%edi
call   1030 <htonl@plt>
mov    %eax,(%rbx)
lea    0x4(%rbx),%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
mov    %r15d,%edi
call   1030 <htonl@plt>
mov    %r12d,%ecx
mov    %eax,0x4(%rbx,%rcx,1)
lea    (%rbx,%rcx,1),%rdi
add    $0x8,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
lea    (%r12,%r15,1),%eax
add    $0x8,%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sig_makefile(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32* %5, i32** %12
%13 = load i32, i32* %8
%14 = call i32 @htonl(i32 %13)
%15 = load i8*, i8** %11
%16 = bitcast i8* %15 to i32*
store i32 %14, i32* %16
%17 = load i8*, i8** %11
%18 = getelementptr inbounds i8, i8* %17, i64 4
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %10
%23 = call i32 @htonl(i32 %22)
%24 = load i8*, i8** %11
%25 = getelementptr inbounds i8, i8* %24, i64 4
%26 = load i32, i32* %8
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = bitcast i8* %28 to i32*
store i32 %23, i32* %29
%30 = load i8*, i8** %11
%31 = getelementptr inbounds i8, i8* %30, i64 4
%32 = load i32, i32* %8
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 4
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i32, i32* %8
%40 = zext i32 %39 to i64
%41 = add i64 4, %40
%42 = add i64 %41, 4
%43 = load i32, i32* %10
%44 = zext i32 %43 to i64
%45 = add i64 %42, %44
%46 = trunc i64 %45 to i32
%47 = load i32*, i32** %12
store i32 %46, i32* %47
ret i32 0
}

LLVM IR (-O2):
define i32 @sig_makefile(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* nocapture writeonly %5) {
%7 = tail call i32 @htonl(i32 %1)
%8 = bitcast i8* %4 to i32*
store i32 %7, i32* %8
%9 = getelementptr inbounds i8, i8* %4, i64 4
%10 = tail call i32 @memcpy(i8* %9, i8* %0, i32 %1)
%11 = tail call i32 @htonl(i32 %3)
%12 = zext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = bitcast i8* %13 to i32*
store i32 %11, i32* %14
%15 = getelementptr inbounds i8, i8* %13, i64 4
%16 = tail call i32 @memcpy(i8* %15, i8* %2, i32 %3)
%17 = add i32 %1, 8
%18 = add i32 %17, %3
store i32 %18, i32* %5
ret i32 0
}