#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 */

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ IPPROTO_ICMPV6;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ loop_on_receive(int, int);
int /*<<< orphan*/ parse_cmdline(int, char **, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int icmp_socket;
  int ip_version;
  parse_cmdline(argc, argv, &ip_version);
  if (ip_version == 6) {
    icmp_socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
  } else {
    icmp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  }
  if (icmp_socket < 0) {
    perror("Failure opening listening socket");
    exit(EXIT_FAILURE);
  }
  printf("status listening\n");
  fflush(stdout);
  loop_on_receive(icmp_socket, ip_version);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <parse_cmdline@plt>
cmpl   $0x6,-0x18(%rbp)
jne    11c8 <main+0x58>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
jmp    11eb <main+0x7b>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120f <main+0x9f>
lea    0xe04(%rip),%rdi
call   1050 <perror@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1080 <loop_on_receive@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdx
call   1060 <parse_cmdline@plt>
cmpl   $0x6,0xc(%rsp)
mov    0x2e5d(%rip),%rax
cmove  0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    0x2e23(%rip),%rax
cmove  0x2e2b(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11ee <main+0x7e>
mov    %eax,%ebx
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    0xc(%rsp),%esi
mov    %ebx,%edi
call   1080 <loop_on_receive@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@AF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@AF_INET = global i32 0
@IPPROTO_ICMP = global i32 0
@.str = [33 x i8] c"Failure opening listening socket\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"status listening\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @parse_cmdline(i32 %8, i8** %9, i32* %7)
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 6
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @AF_INET6
%15 = load i32, i32* @SOCK_RAW
%16 = load i32, i32* @IPPROTO_ICMPV6
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %6
br label %23
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_RAW
%21 = load i32, i32* @IPPROTO_ICMP
%22 = call i32 @socket(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %6
br label %23
23: ; preds = %18, %13
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = call i32 @loop_on_receive(i32 %34, i32 %35)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}

LLVM IR (-O2):
@AF_INET6 = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMPV6 = global i32 0
@AF_INET = global i32 0
@IPPROTO_ICMP = global i32 0
@.str = [33 x i8] c"Failure opening listening socket\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [17 x i8] c"status listening\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @parse_cmdline(i32 %0, i8** %1, i32* %3)
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 6
%8 = load i32, i32* @AF_INET6
%9 = load i32, i32* @AF_INET
%10 = select i1 %7, i32 %8, i32 %9
%11 = load i32, i32* @SOCK_RAW
%12 = load i32, i32* @IPPROTO_ICMPV6
%13 = load i32, i32* @IPPROTO_ICMP
%14 = select i1 %7, i32 %12, i32 %13
%15 = call i32 @socket(i32 %10, i32 %11, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @loop_on_receive(i32 %15, i32 %25)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}