#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 iphdr {
  int ihl;
  int version;
  int tos;
  int frag_off;
  int ttl;
  scalar_t__ tot_len;
  scalar_t__ check;
  void *daddr;
  void *saddr;
  int /*<<< orphan*/ protocol;
  void *id;
};

/* Variables and functions */
scalar_t__ Checksum(unsigned short *, scalar_t__);
int /*<<< orphan*/ IPPROTO_IP;
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
void *htons(int);
void *inet_addr(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
unsigned short *CreateIpv4Packet() {
  char sender_ip[32];
  char destination_ip[32];
  char *data;
  char *datagram = malloc(4096);
  memset(datagram, 0, 4096);
  struct iphdr *iph = (struct iphdr *)datagram;
  data = (char *)datagram + sizeof(struct iphdr);
  strcpy(data, "ABCDEFGHIJK");
  char input[32];
  printf("Creating IPv4 packet (if empty, set default): \n");
  printf("Internet header length (5): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->ihl = 5;
  else
    iph->ihl = atoi(input);
  printf("Version set to: 4. \n");
  iph->version = 4;
  printf("Type of service (0): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->tos = 0;
  else
    iph->tos = atoi(input);
  printf("Total length will be calculated... \n");
  iph->tot_len = sizeof(struct iphdr) + strlen(data);
  printf("ID (54321): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->id = htons(54321);
  else
    iph->id = htons(atoi(input));
  printf("Fragmentation offset (0): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->frag_off = 0;
  else
    iph->frag_off = atoi(input);
  printf("Time to live (64): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->ttl = 64;
  else
    iph->ttl = atoi(input);
  printf("Protocol set to IPv4...\n");
  iph->protocol = IPPROTO_IP;
  printf("Checksum will be calculated...\n");
  iph->check = 0;
  printf("Source address (192.168.1.1): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->saddr = inet_addr("192.168.1.1");
  else
    iph->saddr = inet_addr(input);
  printf("Destination address (8.8.8.8): ");
  fgets(input, 32, stdin);
  if (atoi(input) == 0)
    iph->daddr = inet_addr("8.8.8.8");
  else
    iph->daddr = inet_addr(input);
  printf("Data automaticly set: %s\n", data);
  iph->check = Checksum((unsigned short *)datagram, iph->tot_len);
  return (unsigned short *)datagram;
}


x86 assembly (clang, -O0):
<CreateIpv4Packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rax
add    $0x48,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    1241 <CreateIpv4Packet+0xa1>
mov    -0x58(%rbp),%rax
movl   $0x5,(%rax)
jmp    1252 <CreateIpv4Packet+0xb2>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x58(%rbp),%rax
movl   $0x4,0x4(%rax)
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    12b2 <CreateIpv4Packet+0x112>
mov    -0x58(%rbp),%rax
movl   $0x0,0x8(%rax)
jmp    12c4 <CreateIpv4Packet+0x124>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x8(%rax)
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x48,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x18(%rax)
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    133b <CreateIpv4Packet+0x19b>
mov    $0xd431,%edi
call   1060 <htons@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x40(%rax)
jmp    1356 <CreateIpv4Packet+0x1b6>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x40(%rax)
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2c71(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    139d <CreateIpv4Packet+0x1fd>
mov    -0x58(%rbp),%rax
movl   $0x0,0xc(%rax)
jmp    13af <CreateIpv4Packet+0x20f>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0xc(%rax)
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2c18(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    13f6 <CreateIpv4Packet+0x256>
mov    -0x58(%rbp),%rax
movl   $0x40,0x10(%rax)
jmp    1408 <CreateIpv4Packet+0x268>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x10(%rax)
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2bcb(%rip),%rax
mov    (%rax),%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x38(%rax)
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x58(%rbp),%rax
movq   $0x0,0x20(%rax)
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2b87(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    1493 <CreateIpv4Packet+0x2f3>
lea    0xcbf(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x30(%rax)
jmp    14a7 <CreateIpv4Packet+0x307>
lea    -0x80(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x30(%rax)
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2b20(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1090 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jne    14fa <CreateIpv4Packet+0x35a>
lea    0xc84(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x28(%rax)
jmp    150e <CreateIpv4Packet+0x36e>
lea    -0x80(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x28(%rax)
mov    -0x48(%rbp),%rsi
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <Checksum@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    -0x50(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateIpv4Packet>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x1000,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1090 <memset@plt>
lea    0x48(%rbx),%r14
lea    0xe1e(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
lea    0xef7(%rip),%rdi
call   1050 <puts@plt>
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2dd5(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
mov    $0x5,%ecx
cmovne %eax,%ecx
mov    %ecx,(%rbx)
lea    0xedd(%rip),%rdi
call   1050 <puts@plt>
movl   $0x4,0x4(%rbx)
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
mov    %eax,0x8(%rbx)
lea    0xeb4(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
add    $0x48,%rax
mov    %rax,0x18(%rbx)
lea    0xdac(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
mov    $0xd431,%edi
cmovne %eax,%edi
call   1070 <htons@plt>
mov    %rax,0x40(%rbx)
lea    0xd7f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
mov    %eax,0xc(%rbx)
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
mov    $0x40,%ecx
cmovne %eax,%ecx
mov    %ecx,0x10(%rbx)
lea    0xe24(%rip),%rdi
call   1050 <puts@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rbx)
lea    0xe24(%rip),%rdi
call   1050 <puts@plt>
movq   $0x0,0x20(%rbx)
lea    0xd24(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
je     1380 <CreateIpv4Packet+0x1d0>
mov    %rsp,%rdi
jmp    1387 <CreateIpv4Packet+0x1d7>
lea    0xd13(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,0x30(%rbx)
lea    0xd0f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r12),%edx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
call   10a0 <fgets@plt>
mov    %r15,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
je     13c3 <CreateIpv4Packet+0x213>
mov    %rsp,%rdi
jmp    13ca <CreateIpv4Packet+0x21a>
lea    0xcfc(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,0x28(%rbx)
lea    0xcf4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x18(%rbx),%rsi
mov    %rbx,%rdi
call   1030 <Checksum@plt>
mov    %rax,0x20(%rbx)
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.iphdr = type { i32, i32, i32, i32, i32, i64, i64, i8*, i8*, i32, i8* }
@.str = [12 x i8] c"ABCDEFGHIJK\00"
@.str.1 = [48 x i8] c"Creating IPv4 packet (if empty, set default): \0A\00"
@.str.2 = [29 x i8] c"Internet header length (5): \00"
@stdin = global i32 0
@.str.3 = [21 x i8] c"Version set to: 4. \0A\00"
@.str.4 = [22 x i8] c"Type of service (0): \00"
@.str.5 = [37 x i8] c"Total length will be calculated... \0A\00"
@.str.6 = [13 x i8] c"ID (54321): \00"
@.str.7 = [27 x i8] c"Fragmentation offset (0): \00"
@.str.8 = [20 x i8] c"Time to live (64): \00"
@.str.9 = [25 x i8] c"Protocol set to IPv4...\0A\00"
@IPPROTO_IP = global i32 0
@.str.10 = [32 x i8] c"Checksum will be calculated...\0A\00"
@.str.11 = [31 x i8] c"Source address (192.168.1.1): \00"
@.str.12 = [12 x i8] c"192.168.1.1\00"
@.str.13 = [32 x i8] c"Destination address (8.8.8.8): \00"
@.str.14 = [8 x i8] c"8.8.8.8\00"
@.str.15 = [26 x i8] c"Data automaticly set: %s\0A\00"
define i16* @CreateIpv4Packet() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.iphdr*
%6 = alloca [32 x i8]
%7 = call i8* @malloc(i32 4096)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @memset(i8* %8, i32 0, i32 4096)
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to %struct.iphdr*
store %struct.iphdr* %11, %struct.iphdr** %5
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 72
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 32, i32 %19)
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = load %struct.iphdr*, %struct.iphdr** %5
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %25, i32 0, i32 0
store i32 5, i32* %26
br label %32
27: ; preds = %0
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%29 = call i32 @atoi(i8* %28)
%30 = load %struct.iphdr*, %struct.iphdr** %5
%31 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %30, i32 0, i32 0
store i32 %29, i32* %31
br label %32
32: ; preds = %27, %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%34 = load %struct.iphdr*, %struct.iphdr** %5
%35 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %34, i32 0, i32 1
store i32 4, i32* %35
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* @stdin
%39 = call i32 @fgets(i8* %37, i32 32, i32 %38)
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%41 = call i32 @atoi(i8* %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %32
%44 = load %struct.iphdr*, %struct.iphdr** %5
%45 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %44, i32 0, i32 2
store i32 0, i32* %45
br label %51
46: ; preds = %32
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%48 = call i32 @atoi(i8* %47)
%49 = load %struct.iphdr*, %struct.iphdr** %5
%50 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %49, i32 0, i32 2
store i32 %48, i32* %50
br label %51
51: ; preds = %46, %43
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%53 = load i8*, i8** %3
%54 = call i64 @strlen(i8* %53)
%55 = add i64 72, %54
%56 = load %struct.iphdr*, %struct.iphdr** %5
%57 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %56, i32 0, i32 5
store i64 %55, i64* %57
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%60 = load i32, i32* @stdin
%61 = call i32 @fgets(i8* %59, i32 32, i32 %60)
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%63 = call i32 @atoi(i8* %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %51
%66 = call i8* @htons(i32 54321)
%67 = load %struct.iphdr*, %struct.iphdr** %5
%68 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %67, i32 0, i32 10
store i8* %66, i8** %68
br label %75
69: ; preds = %51
%70 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%71 = call i32 @atoi(i8* %70)
%72 = call i8* @htons(i32 %71)
%73 = load %struct.iphdr*, %struct.iphdr** %5
%74 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %73, i32 0, i32 10
store i8* %72, i8** %74
br label %75
75: ; preds = %69, %65
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%78 = load i32, i32* @stdin
%79 = call i32 @fgets(i8* %77, i32 32, i32 %78)
%80 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%81 = call i32 @atoi(i8* %80)
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %75
%84 = load %struct.iphdr*, %struct.iphdr** %5
%85 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %84, i32 0, i32 3
store i32 0, i32* %85
br label %91
86: ; preds = %75
%87 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%88 = call i32 @atoi(i8* %87)
%89 = load %struct.iphdr*, %struct.iphdr** %5
%90 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %89, i32 0, i32 3
store i32 %88, i32* %90
br label %91
91: ; preds = %86, %83
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%93 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%94 = load i32, i32* @stdin
%95 = call i32 @fgets(i8* %93, i32 32, i32 %94)
%96 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%97 = call i32 @atoi(i8* %96)
%98 = icmp eq i32 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %91
%100 = load %struct.iphdr*, %struct.iphdr** %5
%101 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %100, i32 0, i32 4
store i32 64, i32* %101
br label %107
102: ; preds = %91
%103 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%104 = call i32 @atoi(i8* %103)
%105 = load %struct.iphdr*, %struct.iphdr** %5
%106 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %105, i32 0, i32 4
store i32 %104, i32* %106
br label %107
107: ; preds = %102, %99
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
%109 = load i32, i32* @IPPROTO_IP
%110 = load %struct.iphdr*, %struct.iphdr** %5
%111 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %110, i32 0, i32 9
store i32 %109, i32* %111
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
%113 = load %struct.iphdr*, %struct.iphdr** %5
%114 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %113, i32 0, i32 6
store i64 0, i64* %114
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%116 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%117 = load i32, i32* @stdin
%118 = call i32 @fgets(i8* %116, i32 32, i32 %117)
%119 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%120 = call i32 @atoi(i8* %119)
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %126
122: ; preds = %107
%123 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
%124 = load %struct.iphdr*, %struct.iphdr** %5
%125 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %124, i32 0, i32 8
store i8* %123, i8** %125
br label %131
126: ; preds = %107
%127 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%128 = call i8* @inet_addr(i8* %127)
%129 = load %struct.iphdr*, %struct.iphdr** %5
%130 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %129, i32 0, i32 8
store i8* %128, i8** %130
br label %131
131: ; preds = %126, %122
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%133 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%134 = load i32, i32* @stdin
%135 = call i32 @fgets(i8* %133, i32 32, i32 %134)
%136 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%137 = call i32 @atoi(i8* %136)
%138 = icmp eq i32 %137, 0
br i1 %138, label %139, label %143
139: ; preds = %131
%140 = call i8* @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
%141 = load %struct.iphdr*, %struct.iphdr** %5
%142 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %141, i32 0, i32 7
store i8* %140, i8** %142
br label %148
143: ; preds = %131
%144 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%145 = call i8* @inet_addr(i8* %144)
%146 = load %struct.iphdr*, %struct.iphdr** %5
%147 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %146, i32 0, i32 7
store i8* %145, i8** %147
br label %148
148: ; preds = %143, %139
%149 = load i8*, i8** %3
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i64 0, i64 0), i8* %149)
%151 = load i8*, i8** %4
%152 = bitcast i8* %151 to i16*
%153 = load %struct.iphdr*, %struct.iphdr** %5
%154 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %153, i32 0, i32 5
%155 = load i64, i64* %154
%156 = call i64 @Checksum(i16* %152, i64 %155)
%157 = load %struct.iphdr*, %struct.iphdr** %5
%158 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %157, i32 0, i32 6
store i64 %156, i64* %158
%159 = load i8*, i8** %4
%160 = bitcast i8* %159 to i16*
ret i16* %160
}

LLVM IR (-O2):
%struct.iphdr = type { i32, i32, i32, i32, i32, i64, i64, i8*, i8*, i32, i8* }
@.str = [12 x i8] c"ABCDEFGHIJK\00"
@.str.2 = [29 x i8] c"Internet header length (5): \00"
@stdin = global i32 0
@.str.4 = [22 x i8] c"Type of service (0): \00"
@.str.6 = [13 x i8] c"ID (54321): \00"
@.str.7 = [27 x i8] c"Fragmentation offset (0): \00"
@.str.8 = [20 x i8] c"Time to live (64): \00"
@IPPROTO_IP = global i32 0
@.str.11 = [31 x i8] c"Source address (192.168.1.1): \00"
@.str.12 = [12 x i8] c"192.168.1.1\00"
@.str.13 = [32 x i8] c"Destination address (8.8.8.8): \00"
@.str.14 = [8 x i8] c"8.8.8.8\00"
@.str.15 = [26 x i8] c"Data automaticly set: %s\0A\00"
@str = [47 x i8] c"Creating IPv4 packet (if empty, set default): \00"
@str.16 = [20 x i8] c"Version set to: 4. \00"
@str.17 = [36 x i8] c"Total length will be calculated... \00"
@str.18 = [24 x i8] c"Protocol set to IPv4...\00"
@str.19 = [31 x i8] c"Checksum will be calculated...\00"
define i16* @CreateIpv4Packet() {
%1 = alloca [32 x i8]
%2 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%3 = tail call i32 @memset(i8* %2, i32 0, i32 4096)
%4 = bitcast i8* %2 to %struct.iphdr*
%5 = getelementptr inbounds i8, i8* %2, i64 72
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %7, i32 32, i32 %10)
%12 = call i32 @atoi(i8* %7)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 5, i32 %12
%15 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.16, i64 0, i64 0))
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 1
store i32 4, i32* %17
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %7, i32 32, i32 %19)
%21 = call i32 @atoi(i8* %7)
%22 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.17, i64 0, i64 0))
%24 = call i64 @strlen(i8* %5)
%25 = add i64 %24, 72
%26 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 5
store i64 %25, i64* %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %7, i32 32, i32 %28)
%30 = call i32 @atoi(i8* %7)
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i32 54321, i32 %30
%33 = call i8* @htons(i32 %32)
%34 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 10
store i8* %33, i8** %34
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %7, i32 32, i32 %36)
%38 = call i32 @atoi(i8* %7)
%39 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 3
store i32 %38, i32* %39
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %7, i32 32, i32 %41)
%43 = call i32 @atoi(i8* %7)
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 64, i32 %43
%46 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 4
store i32 %45, i32* %46
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.18, i64 0, i64 0))
%48 = load i32, i32* @IPPROTO_IP
%49 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 9
store i32 %48, i32* %49
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.19, i64 0, i64 0))
%51 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 6
store i64 0, i64* %51
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0))
%53 = load i32, i32* @stdin
%54 = call i32 @fgets(i8* %7, i32 32, i32 %53)
%55 = call i32 @atoi(i8* %7)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %0
%58 = call i8* @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
br label %61
59: ; preds = %0
%60 = call i8* @inet_addr(i8* %7)
br label %61
61: ; preds = %59, %57
%62 = phi i8* [ %58, %57 ], [ %60, %59 ]
%63 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 8
store i8* %62, i8** %63
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%65 = load i32, i32* @stdin
%66 = call i32 @fgets(i8* %7, i32 32, i32 %65)
%67 = call i32 @atoi(i8* %7)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %61
%70 = call i8* @inet_addr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %73
71: ; preds = %61
%72 = call i8* @inet_addr(i8* %7)
br label %73
73: ; preds = %71, %69
%74 = phi i8* [ %70, %69 ], [ %72, %71 ]
%75 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i64 0, i32 7
store i8* %74, i8** %75
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.15, i64 0, i64 0), i8* %5)
%77 = bitcast i8* %2 to i16*
%78 = load i64, i64* %26
%79 = call i64 @Checksum(i16* %77, i64 %78)
store i64 %79, i64* %51
ret i16* %77
}