#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 int /*<<< orphan*/ u_short;
struct iphdr {
  int igmp_type;
  int igmp_code;
  scalar_t__ igmp_cksum;
};
typedef struct iphdr u_char;
struct igmp {
  int igmp_type;
  int igmp_code;
  scalar_t__ igmp_cksum;
};
typedef int /*<<< orphan*/ packet;
typedef int /*<<< orphan*/ ip;

/* Variables and functions */
int /*<<< orphan*/ CompileIPhdr(struct iphdr *, char *, char *,
                                int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ IPPROTO_IGMP;
int /*<<< orphan*/ free(struct iphdr *);
int /*<<< orphan*/ getuid();
scalar_t__ in_cksum(int /*<<< orphan*/ *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(struct iphdr *, struct iphdr *, int);
int /*<<< orphan*/ memset(struct iphdr *, int /*<<< orphan*/, int);
int CompileIGMPacket(char *soAddr, char *dAddr, int igmpType,
                     int igmpRoutinCode, u_char *rPckt) {
  struct iphdr ip;
  struct igmp igmp;
  u_char *packet;
  packet = (u_char *)malloc(sizeof(struct iphdr) + sizeof(struct igmp));
  memset(packet, 0, sizeof(packet));
  CompileIPhdr(&ip, soAddr, dAddr, IPPROTO_IGMP, getuid());
  memcpy(packet, &ip, sizeof(ip));
  igmp.igmp_type = igmpType;
  igmp.igmp_code = igmpRoutinCode;
  igmp.igmp_cksum = 0;
  igmp.igmp_cksum = in_cksum((u_short *)&igmp, sizeof(struct igmp));
  memcpy(packet + sizeof(struct iphdr), &igmp, sizeof(struct igmp));
  memcpy(rPckt, packet, sizeof(struct iphdr) + sizeof(struct igmp));
  free(packet);
  return 1;
}


x86 assembly (clang, -O0):
<CompileIGMPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    $0x20,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1060 <getuid@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x4c(%rbp),%ecx
mov    %eax,%r8d
lea    -0x30(%rbp),%rdi
call   1050 <CompileIPhdr@plt>
mov    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   1040 <in_cksum@plt>
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x100,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CompileIGMPacket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x20(%rsp)
mov    %ecx,0xc(%rsp)
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x20,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1060 <getuid@plt>
lea    0x28(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    %r14d,%ecx
mov    %eax,%r8d
call   1050 <CompileIPhdr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    %r12d,0x10(%rsp)
mov    0xc(%rsp),%eax
mov    %eax,0x14(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
call   1040 <in_cksum@plt>
mov    %rax,0x18(%rsp)
lea    0x100(%rbx),%rdi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1080 <memcpy@plt>
mov    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1080 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i64 }
%struct.igmp = type { i32, i32, i64 }
@IPPROTO_IGMP = global i32 0
define i32 @CompileIGMPacket(i8* %0, i8* %1, i32 %2, i32 %3, %struct.iphdr* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.iphdr*
%11 = alloca %struct.iphdr
%12 = alloca %struct.igmp
%13 = alloca %struct.iphdr*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store %struct.iphdr* %4, %struct.iphdr** %10
%14 = call i64 @malloc(i32 32)
%15 = inttoptr i64 %14 to %struct.iphdr*
store %struct.iphdr* %15, %struct.iphdr** %13
%16 = load %struct.iphdr*, %struct.iphdr** %13
%17 = call i32 @memset(%struct.iphdr* %16, i32 0, i32 8)
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = load i32, i32* @IPPROTO_IGMP
%21 = call i32 (...) @getuid()
%22 = call i32 @CompileIPhdr(%struct.iphdr* %11, i8* %18, i8* %19, i32 %20, i32 %21)
%23 = load %struct.iphdr*, %struct.iphdr** %13
%24 = call i32 @memcpy(%struct.iphdr* %23, %struct.iphdr* %11, i32 16)
%25 = load i32, i32* %8
%26 = getelementptr inbounds %struct.igmp, %struct.igmp* %12, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %9
%28 = getelementptr inbounds %struct.igmp, %struct.igmp* %12, i32 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.igmp, %struct.igmp* %12, i32 0, i32 2
store i64 0, i64* %29
%30 = bitcast %struct.igmp* %12 to i32*
%31 = call i64 @in_cksum(i32* %30, i32 16)
%32 = getelementptr inbounds %struct.igmp, %struct.igmp* %12, i32 0, i32 2
store i64 %31, i64* %32
%33 = load %struct.iphdr*, %struct.iphdr** %13
%34 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %33, i64 16
%35 = bitcast %struct.igmp* %12 to %struct.iphdr*
%36 = call i32 @memcpy(%struct.iphdr* %34, %struct.iphdr* %35, i32 16)
%37 = load %struct.iphdr*, %struct.iphdr** %10
%38 = load %struct.iphdr*, %struct.iphdr** %13
%39 = call i32 @memcpy(%struct.iphdr* %37, %struct.iphdr* %38, i32 32)
%40 = load %struct.iphdr*, %struct.iphdr** %13
%41 = call i32 @free(%struct.iphdr* %40)
ret i32 1
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i64 }
%struct.igmp = type { i32, i32, i64 }
@IPPROTO_IGMP = global i32 0
define i32 @CompileIGMPacket(i8* %0, i8* %1, i32 %2, i32 %3, %struct.iphdr* %4) {
%6 = alloca %struct.iphdr
%7 = alloca %struct.igmp
%8 = bitcast %struct.iphdr* %6 to i8*
%9 = bitcast %struct.igmp* %7 to i8*
%10 = tail call i64 @malloc(i32 32)
%11 = inttoptr i64 %10 to %struct.iphdr*
%12 = tail call i32 @memset(%struct.iphdr* %11, i32 0, i32 8)
%13 = load i32, i32* @IPPROTO_IGMP
%14 = tail call i32 (...) @getuid()
%15 = call i32 @CompileIPhdr(%struct.iphdr* %6, i8* %0, i8* %1, i32 %13, i32 %14)
%16 = call i32 @memcpy(%struct.iphdr* %11, %struct.iphdr* %6, i32 16)
%17 = getelementptr inbounds %struct.igmp, %struct.igmp* %7, i64 0, i32 0
store i32 %2, i32* %17
%18 = getelementptr inbounds %struct.igmp, %struct.igmp* %7, i64 0, i32 1
store i32 %3, i32* %18
%19 = getelementptr inbounds %struct.igmp, %struct.igmp* %7, i64 0, i32 2
store i64 0, i64* %19
%20 = call i64 @in_cksum(i32* %17, i32 16)
store i64 %20, i64* %19
%21 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %11, i64 16
%22 = bitcast %struct.igmp* %7 to %struct.iphdr*
%23 = call i32 @memcpy(%struct.iphdr* %21, %struct.iphdr* %22, i32 16)
%24 = call i32 @memcpy(%struct.iphdr* %4, %struct.iphdr* %11, i32 32)
%25 = call i32 @free(%struct.iphdr* %11)
ret i32 1
}