#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct TYPE_2__ {
  char s_addr;
};
struct sockaddr_in {
  char sin_port;
  TYPE_1__ sin_addr;
};

/* Variables and functions */
unsigned int crc32(long, unsigned char *, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, ...);
int /*<<< orphan*/ printf(char *, int, scalar_t__);
int strlen(char *);
int buildMessage(struct sockaddr_in *addr, char *msg1, char *msg, char **dg) {
  struct timeval start, end;
  char *ptr = malloc(sizeof(char) * (14 + strlen(msg)));
  gettimeofday(&start, NULL);
  unsigned int crc32_value = crc32(0L, (unsigned char *)msg1, strlen(msg1));
  gettimeofday(&end, NULL);
  printf("crc_time\t%lu\t%lu\n", 14 + strlen(msg),
         ((end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec));
  int msg_len = strlen(msg);
  *dg = ptr;
  memcpy(ptr, &(addr->sin_addr.s_addr), sizeof(unsigned int));
  ptr += sizeof(unsigned int);
  memcpy(ptr, &(addr->sin_port), sizeof(short));
  ptr += sizeof(short);
  memcpy(ptr, &msg_len, sizeof(int));
  ptr += sizeof(int);
  memcpy(ptr, &crc32_value, sizeof(int));
  ptr += sizeof(int);
  memcpy(ptr, msg, strlen(msg));
  return 14 + strlen(msg);
}


x86 assembly (clang, -O0):
<buildMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xe,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%edi
call   1030 <crc32@plt>
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
add    $0xe,%esi
mov    -0x40(%rbp),%eax
sub    -0x30(%rbp),%eax
imul   $0xf4240,%eax,%eax
movslq %eax,%rdx
add    -0x38(%rbp),%rdx
sub    -0x28(%rbp),%rdx
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
xor    %eax,%eax
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    $0x2,%edx
call   1070 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
lea    -0x50(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    -0x48(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xe,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildMessage>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
lea    0xe(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
xor    %edi,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <crc32@plt>
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe(%rax),%esi
movslq 0x10(%rsp),%rax
movslq 0x20(%rsp),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rax
mov    0x18(%rsp),%rdx
sub    0x28(%rsp),%rdx
add    %rax,%rdx
lea    0xe11(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,0x8(%rsp)
mov    %rbx,(%r12)
lea    0x1(%r15),%rsi
mov    $0x4,%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <memcpy@plt>
lea    0x4(%rbx),%rdi
mov    $0x2,%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <memcpy@plt>
lea    0x6(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
lea    0xa(%rbx),%rdi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
add    $0xe,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <memcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0xe,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8 }
%struct.timeval = type { i32, i64 }
@.str = [18 x i8] c"crc_time\09%lu\09%lu\0A\00"
define i32 @buildMessage(%struct.sockaddr_in* %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca %struct.sockaddr_in*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8** %3, i8*** %8
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 14, %15
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %11
%21 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @crc32(i64 0, i8* %22, i32 %24)
store i32 %25, i32* %12
%26 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%27 = load i8*, i8** %7
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 14, %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%33 = load i32, i32* %32
%34 = sub nsw i32 %31, %33
%35 = mul nsw i32 %34, 1000000
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%38 = load i64, i64* %37
%39 = add nsw i64 %36, %38
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%41 = load i64, i64* %40
%42 = sub nsw i64 %39, %41
%43 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %29, i64 %42)
%44 = load i8*, i8** %7
%45 = call i32 @strlen(i8* %44)
store i32 %45, i32* %13
%46 = load i8*, i8** %11
%47 = load i8**, i8*** %8
store i8* %46, i8** %47
%48 = load i8*, i8** %11
%49 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %49, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
%52 = call i32 (i8*, ...) @memcpy(i8* %48, i8* %51, i64 4)
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i64 4
store i8* %54, i8** %11
%55 = load i8*, i8** %11
%56 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %56, i32 0, i32 0
%58 = call i32 (i8*, ...) @memcpy(i8* %55, i8* %57, i64 2)
%59 = load i8*, i8** %11
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8* %60, i8** %11
%61 = load i8*, i8** %11
%62 = call i32 (i8*, ...) @memcpy(i8* %61, i32* %13, i64 4)
%63 = load i8*, i8** %11
%64 = getelementptr inbounds i8, i8* %63, i64 4
store i8* %64, i8** %11
%65 = load i8*, i8** %11
%66 = call i32 (i8*, ...) @memcpy(i8* %65, i32* %12, i64 4)
%67 = load i8*, i8** %11
%68 = getelementptr inbounds i8, i8* %67, i64 4
store i8* %68, i8** %11
%69 = load i8*, i8** %11
%70 = load i8*, i8** %7
%71 = load i8*, i8** %7
%72 = call i32 @strlen(i8* %71)
%73 = call i32 (i8*, ...) @memcpy(i8* %69, i8* %70, i32 %72)
%74 = load i8*, i8** %7
%75 = call i32 @strlen(i8* %74)
%76 = add nsw i32 14, %75
ret i32 %76
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i8 }
%struct.timeval = type { i32, i64 }
@.str = [18 x i8] c"crc_time\09%lu\09%lu\0A\00"
define i32 @buildMessage(%struct.sockaddr_in* %0, i8* %1, i8* %2, i8** nocapture writeonly %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
%9 = bitcast %struct.timeval* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = tail call i32 @strlen(i8* %2)
%12 = add nsw i32 %11, 14
%13 = tail call i8* @malloc(i32 %12)
%14 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%15 = bitcast i32* %7 to i8*
%16 = tail call i32 @strlen(i8* %1)
%17 = tail call i32 @crc32(i64 0, i8* %1, i32 %16)
store i32 %17, i32* %7
%18 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%19 = tail call i32 @strlen(i8* %2)
%20 = add nsw i32 %19, 14
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%24 = load i32, i32* %23
%25 = sub nsw i32 %22, %24
%26 = mul nsw i32 %25, 1000000
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%31 = load i64, i64* %30
%32 = sub i64 %29, %31
%33 = add i64 %32, %27
%34 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %20, i64 %33)
%35 = bitcast i32* %8 to i8*
%36 = tail call i32 @strlen(i8* %2)
store i32 %36, i32* %8
store i8* %13, i8** %3
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1, i32 0
%38 = tail call i32 (i8*, ...) @memcpy(i8* %13, i8* %37, i64 4)
%39 = getelementptr inbounds i8, i8* %13, i64 4
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%41 = tail call i32 (i8*, ...) @memcpy(i8* %39, i8* %40, i64 2)
%42 = getelementptr inbounds i8, i8* %13, i64 6
%43 = call i32 (i8*, ...) @memcpy(i8* %42, i32* %8, i64 4)
%44 = getelementptr inbounds i8, i8* %13, i64 10
%45 = call i32 (i8*, ...) @memcpy(i8* %44, i32* %7, i64 4)
%46 = getelementptr inbounds i8, i8* %13, i64 14
%47 = call i32 @strlen(i8* %2)
%48 = call i32 (i8*, ...) @memcpy(i8* %46, i8* %2, i32 %47)
%49 = call i32 @strlen(i8* %2)
%50 = add nsw i32 %49, 14
ret i32 %50
}