#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_3__ {
  int /*<<< orphan*/ id;
};
struct TYPE_4__ {
  TYPE_1__ echo;
};
struct icmphdr {
  int /*<<< orphan*/ checksum;
  TYPE_2__ un;
  scalar_t__ code;
  int /*<<< orphan*/ type;
};

/* Variables and functions */
int /*<<< orphan*/ ICMP_ECHO;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(struct icmphdr *, int, int);
int /*<<< orphan*/ ping_cheksum(int /*<<< orphan*/ *, int);
int rand();
void init_icmphdr(struct icmphdr *icmp, int dlen) {
  memset(icmp, 0, sizeof(struct icmphdr));
  icmp->type = ICMP_ECHO;
  icmp->code = 0;
  icmp->un.echo.id = getpid();
  memset(icmp + sizeof(struct icmphdr), rand() % 255, dlen);
  icmp->checksum =
      ping_cheksum((uint16_t *)icmp, sizeof(struct icmphdr) + dlen);
}


x86 assembly (clang, -O0):
<init_icmphdr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
add    $0x240,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x18(%rbp),%rdi
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    -0xc(%rbp),%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    $0x18,%rax
mov    %eax,%esi
call   1050 <ping_cheksum@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_icmphdr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
movq   $0x0,0x8(%rbx)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x4(%rbx)
lea    0x240(%rbx),%r14
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0x7,%esi
add    %ecx,%esi
mov    %esi,%ecx
shl    $0x8,%ecx
sub    %ecx,%esi
add    %eax,%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <memset@plt>
add    $0x18,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <ping_cheksum@plt>
mov    %eax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.icmphdr = type { i32, %struct.TYPE_4__, i64, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@ICMP_ECHO = global i32 0
define void @init_icmphdr(%struct.icmphdr* %0, i32 %1) {
%3 = alloca %struct.icmphdr*
%4 = alloca i32
store %struct.icmphdr* %0, %struct.icmphdr** %3
store i32 %1, i32* %4
%5 = load %struct.icmphdr*, %struct.icmphdr** %3
%6 = call i32 @memset(%struct.icmphdr* %5, i32 0, i32 24)
%7 = load i32, i32* @ICMP_ECHO
%8 = load %struct.icmphdr*, %struct.icmphdr** %3
%9 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %8, i32 0, i32 3
store i32 %7, i32* %9
%10 = load %struct.icmphdr*, %struct.icmphdr** %3
%11 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %10, i32 0, i32 2
store i64 0, i64* %11
%12 = call i32 (...) @getpid()
%13 = load %struct.icmphdr*, %struct.icmphdr** %3
%14 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %13, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %14, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 0
store i32 %12, i32* %16
%17 = load %struct.icmphdr*, %struct.icmphdr** %3
%18 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %17, i64 24
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 255
%21 = load i32, i32* %4
%22 = call i32 @memset(%struct.icmphdr* %18, i32 %20, i32 %21)
%23 = load %struct.icmphdr*, %struct.icmphdr** %3
%24 = bitcast %struct.icmphdr* %23 to i32*
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = add i64 24, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @ping_cheksum(i32* %24, i32 %28)
%30 = load %struct.icmphdr*, %struct.icmphdr** %3
%31 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %30, i32 0, i32 0
store i32 %29, i32* %31
ret void
}

LLVM IR (-O2):
%struct.icmphdr = type { i32, %struct.TYPE_4__, i64, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@ICMP_ECHO = global i32 0
define void @init_icmphdr(%struct.icmphdr* %0, i32 %1) {
%3 = tail call i32 @memset(%struct.icmphdr* %0, i32 0, i32 24)
%4 = load i32, i32* @ICMP_ECHO
%5 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %0, i64 0, i32 3
store i32 %4, i32* %5
%6 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %0, i64 0, i32 2
store i64 0, i64* %6
%7 = tail call i32 (...) @getpid()
%8 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %0, i64 0, i32 1, i32 0, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.icmphdr, %struct.icmphdr* %0, i64 24
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 255
%12 = tail call i32 @memset(%struct.icmphdr* %9, i32 %11, i32 %1)
%13 = getelementptr %struct.icmphdr, %struct.icmphdr* %0, i64 0, i32 0
%14 = add i32 %1, 24
%15 = tail call i32 @ping_cheksum(i32* %13, i32 %14)
store i32 %15, i32* %13
ret void
}