#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 */
struct timeval {
  int dummy;
};
struct in_addr {
  int dummy;
};
struct ip {
  int ip_v;
  int ip_hl;
  int ip_ttl;
  int ip_p;
  int ip_len;
  scalar_t__ ip_sum;
  int /*<<< orphan*/ ip_id;
  scalar_t__ ip_tos;
  struct in_addr ip_src;
};
struct icmp {
  int icmp_seq;
  int icmp_type;
  scalar_t__ icmp_code;
  scalar_t__ icmp_cksum;
};

/* Variables and functions */
#define ICMP_MASKREQ 129
#define ICMP_TSTAMP 128
int /*<<< orphan*/ bzero(struct icmp *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ stderr;
int initpacket(char *buf, int querytype, struct in_addr fromaddr) {
  struct ip *ip = (struct ip *)buf;
  struct icmp *icmp = (struct icmp *)(ip + 1);
  int icmplen = 0;
  ip->ip_src = fromaddr;
  ip->ip_v = 4;
  ip->ip_hl = sizeof *ip >> 2;
  ip->ip_tos = 0;
  ip->ip_id = htons(4321);
  ip->ip_ttl = 255;
  ip->ip_p = 1;
  ip->ip_sum = 0;
  icmp->icmp_seq = 1;
  icmp->icmp_cksum = 0;
  icmp->icmp_type = querytype;
  icmp->icmp_code = 0;
  switch (querytype) {
  case ICMP_TSTAMP:
    gettimeofday((struct timeval *)(icmp + 8), NULL);
    bzero(icmp + 12, 8);
    icmplen = 20;
    break;
  case ICMP_MASKREQ:
    *((char *)(icmp + 8)) = 255;
    icmplen = 12;
    break;
  default:
    fprintf(stderr, "eek: unknown query type\n");
    exit(0);
  }
  ip->ip_len = sizeof(struct ip) + icmplen;
  return icmplen;
}


x86 assembly (clang, -O0):
<initpacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edx,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x38,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,0x30(%rax)
mov    -0x20(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x20(%rbp),%rax
movl   $0xe,0x4(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    $0x10e1,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x20(%rax)
mov    -0x20(%rbp),%rax
movl   $0xff,0x8(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x80,%eax
je     1232 <initpacket+0xe2>
jmp    121f <initpacket+0xcf>
mov    -0x30(%rbp),%eax
sub    $0x81,%eax
je     1267 <initpacket+0x117>
jmp    127e <initpacket+0x12e>
mov    -0x28(%rbp),%rdi
add    $0xc0,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%rdi
add    $0x120,%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
movl   $0x14,-0x2c(%rbp)
jmp    129a <initpacket+0x14a>
mov    -0x28(%rbp),%rax
movb   $0xff,0xc0(%rax)
movl   $0xc,-0x2c(%rbp)
jmp    129a <initpacket+0x14a>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movslq -0x2c(%rbp),%rax
add    $0x38,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initpacket>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %edx,0x30(%rdi)
movabs $0xe00000004,%rax
mov    %rax,(%rdi)
movq   $0x0,0x28(%rdi)
mov    $0x10e1,%edi
call   1030 <htons@plt>
mov    %eax,0x20(%rbx)
movabs $0x1000000ff,%rax
mov    %rax,0x8(%rbx)
movq   $0x0,0x18(%rbx)
movl   $0x1,0x38(%rbx)
mov    %ebp,0x3c(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rbx)
cmp    $0x81,%ebp
je     11da <initpacket+0x8a>
cmp    $0x80,%ebp
jne    11f3 <initpacket+0xa3>
lea    0xf8(%rbx),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x158(%rbx),%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
mov    $0x14,%eax
jmp    11e6 <initpacket+0x96>
movb   $0xff,0xf8(%rbx)
mov    $0xc,%eax
lea    0x38(%rax),%ecx
mov    %ecx,0x10(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.ip = type { i32, i32, i32, i32, i32, i64, i32, i64, %struct.in_addr }
%struct.icmp = type { i32, i32, i64, i64 }
%struct.timeval = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"eek: unknown query type\0A\00"
define i32 @initpacket(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.in_addr
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.ip*
%8 = alloca %struct.icmp*
%9 = alloca i32
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %4, i32 0, i32 0
store i32 %2, i32* %10
store i8* %0, i8** %5
store i32 %1, i32* %6
%11 = load i8*, i8** %5
%12 = bitcast i8* %11 to %struct.ip*
store %struct.ip* %12, %struct.ip** %7
%13 = load %struct.ip*, %struct.ip** %7
%14 = getelementptr inbounds %struct.ip, %struct.ip* %13, i64 1
%15 = bitcast %struct.ip* %14 to %struct.icmp*
store %struct.icmp* %15, %struct.icmp** %8
store i32 0, i32* %9
%16 = load %struct.ip*, %struct.ip** %7
%17 = getelementptr inbounds %struct.ip, %struct.ip* %16, i32 0, i32 8
%18 = bitcast %struct.in_addr* %17 to i8*
%19 = bitcast %struct.in_addr* %4 to i8*
%20 = load %struct.ip*, %struct.ip** %7
%21 = getelementptr inbounds %struct.ip, %struct.ip* %20, i32 0, i32 0
store i32 4, i32* %21
%22 = load %struct.ip*, %struct.ip** %7
%23 = getelementptr inbounds %struct.ip, %struct.ip* %22, i32 0, i32 1
store i32 14, i32* %23
%24 = load %struct.ip*, %struct.ip** %7
%25 = getelementptr inbounds %struct.ip, %struct.ip* %24, i32 0, i32 7
store i64 0, i64* %25
%26 = call i32 @htons(i32 4321)
%27 = load %struct.ip*, %struct.ip** %7
%28 = getelementptr inbounds %struct.ip, %struct.ip* %27, i32 0, i32 6
store i32 %26, i32* %28
%29 = load %struct.ip*, %struct.ip** %7
%30 = getelementptr inbounds %struct.ip, %struct.ip* %29, i32 0, i32 2
store i32 255, i32* %30
%31 = load %struct.ip*, %struct.ip** %7
%32 = getelementptr inbounds %struct.ip, %struct.ip* %31, i32 0, i32 3
store i32 1, i32* %32
%33 = load %struct.ip*, %struct.ip** %7
%34 = getelementptr inbounds %struct.ip, %struct.ip* %33, i32 0, i32 5
store i64 0, i64* %34
%35 = load %struct.icmp*, %struct.icmp** %8
%36 = getelementptr inbounds %struct.icmp, %struct.icmp* %35, i32 0, i32 0
store i32 1, i32* %36
%37 = load %struct.icmp*, %struct.icmp** %8
%38 = getelementptr inbounds %struct.icmp, %struct.icmp* %37, i32 0, i32 3
store i64 0, i64* %38
%39 = load i32, i32* %6
%40 = load %struct.icmp*, %struct.icmp** %8
%41 = getelementptr inbounds %struct.icmp, %struct.icmp* %40, i32 0, i32 1
store i32 %39, i32* %41
%42 = load %struct.icmp*, %struct.icmp** %8
%43 = getelementptr inbounds %struct.icmp, %struct.icmp* %42, i32 0, i32 2
store i64 0, i64* %43
%44 = load i32, i32* %6
switch i32 %44, label %57 [
i32 128, label %45
i32 129, label %53
]
45: ; preds = %3
%46 = load %struct.icmp*, %struct.icmp** %8
%47 = getelementptr inbounds %struct.icmp, %struct.icmp* %46, i64 8
%48 = bitcast %struct.icmp* %47 to %struct.timeval*
%49 = call i32 @gettimeofday(%struct.timeval* %48, i32* null)
%50 = load %struct.icmp*, %struct.icmp** %8
%51 = getelementptr inbounds %struct.icmp, %struct.icmp* %50, i64 12
%52 = call i32 @bzero(%struct.icmp* %51, i32 8)
store i32 20, i32* %9
br label %61
53: ; preds = %3
%54 = load %struct.icmp*, %struct.icmp** %8
%55 = getelementptr inbounds %struct.icmp, %struct.icmp* %54, i64 8
%56 = bitcast %struct.icmp* %55 to i8*
store i8 -1, i8* %56
store i32 12, i32* %9
br label %61
57: ; preds = %3
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %53, %45
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = add i64 56, %63
%65 = trunc i64 %64 to i32
%66 = load %struct.ip*, %struct.ip** %7
%67 = getelementptr inbounds %struct.ip, %struct.ip* %66, i32 0, i32 4
store i32 %65, i32* %67
%68 = load i32, i32* %9
ret i32 %68
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.icmp = type { i32, i32, i64, i64 }
@stderr = global i32 0
@.str = [25 x i8] c"eek: unknown query type\0A\00"
define i32 @initpacket(i8* nocapture %0, i32 %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 56
%5 = getelementptr inbounds i8, i8* %0, i64 48
%6 = bitcast i8* %5 to i32*
store i32 %2, i32* %6
%7 = bitcast i8* %0 to i32*
store i32 4, i32* %7
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = bitcast i8* %8 to i32*
store i32 14, i32* %9
%10 = getelementptr inbounds i8, i8* %0, i64 40
%11 = bitcast i8* %10 to i64*
store i64 0, i64* %11
%12 = tail call i32 @htons(i32 4321)
%13 = getelementptr inbounds i8, i8* %0, i64 32
%14 = bitcast i8* %13 to i32*
store i32 %12, i32* %14
%15 = getelementptr inbounds i8, i8* %0, i64 8
%16 = bitcast i8* %15 to i32*
store i32 255, i32* %16
%17 = getelementptr inbounds i8, i8* %0, i64 12
%18 = bitcast i8* %17 to i32*
store i32 1, i32* %18
%19 = getelementptr inbounds i8, i8* %0, i64 24
%20 = bitcast i8* %19 to i64*
store i64 0, i64* %20
%21 = bitcast i8* %4 to i32*
store i32 1, i32* %21
%22 = getelementptr inbounds i8, i8* %0, i64 60
%23 = bitcast i8* %22 to i32*
store i32 %1, i32* %23
%24 = getelementptr inbounds i8, i8* %0, i64 64
%25 = bitcast i8* %24 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %25
switch i32 %1, label %35 [
i32 128, label %26
i32 129, label %33
]
26: ; preds = %3
%27 = getelementptr inbounds i8, i8* %0, i64 248
%28 = bitcast i8* %27 to %struct.timeval*
%29 = tail call i32 @gettimeofday(%struct.timeval* %28, i32* null)
%30 = getelementptr inbounds i8, i8* %0, i64 344
%31 = bitcast i8* %30 to %struct.icmp*
%32 = tail call i32 @bzero(%struct.icmp* %31, i32 8)
br label %39
33: ; preds = %3
%34 = getelementptr inbounds i8, i8* %0, i64 248
store i8 -1, i8* %34
br label %39
35: ; preds = %3
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%38 = tail call i32 @exit(i32 0)
unreachable
39: ; preds = %33, %26
%40 = phi i32 [ 12, %33 ], [ 20, %26 ]
%41 = add nuw nsw i32 %40, 56
%42 = getelementptr inbounds i8, i8* %0, i64 16
%43 = bitcast i8* %42 to i32*
store i32 %41, i32* %43
ret i32 %40
}