#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 sockaddr_in {
  int sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct icmphdr {
  int dummy;
};
struct icmp {
  scalar_t__ icmp_ttime;
  void *icmp_seq;
  scalar_t__ icmp_id;
  void *icmp_cksum;
  scalar_t__ icmp_code;
  int /*<<< orphan*/ icmp_type;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ icmp_hdr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ ICMP_ECHO;
int /*<<< orphan*/ IPPROTO_ICMP;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
scalar_t__ geteuid();
void *htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, struct icmp *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, ret;
  int sock_icmp;
  struct ip;
  struct icmp icmp_hdr;
  struct sockaddr_in sin;
  if (geteuid()) {
    printf("\n----\nError 1: Root yourself"
           "\nExiting...\n");
    return -1;
  }
  if ((sock_icmp = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) {
    perror("Icmp error");
    return sock_icmp;
  }
  sin.sin_port = 7;
  sin.sin_family = AF_INET;
  inet_pton(AF_INET, "8.8.8.8", &sin.sin_addr);
  icmp_hdr.icmp_type = ICMP_ECHO;
  icmp_hdr.icmp_code = 0;
  icmp_hdr.icmp_cksum = htons(0xF7FE);
  icmp_hdr.icmp_id = 0;
  icmp_hdr.icmp_seq = htons(1);
  icmp_hdr.icmp_ttime = 0;
  if ((ret < sendto(sock_icmp, &icmp_hdr, sizeof(struct icmphdr), 0,
                    (struct sockaddr *)&sin, sizeof(sin)))) {
    perror("sendto");
  }
  printf("\n%u", sizeof(icmp_hdr));
  close(sock_icmp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    $0x0,%rax
je     11c1 <main+0x41>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d2 <main+0x152>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1204 <main+0x84>
lea    0xe35(%rip),%rdi
call   1090 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d2 <main+0x152>
movl   $0x7,-0x60(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
add    $0x4,%rdx
lea    0xe05(%rip),%rsi
call   1080 <inet_pton@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0xf7fe,%edi
call   1030 <htons@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    $0x1,%edi
call   1030 <htons@plt>
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%r8
lea    -0x50(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
cmp    %ecx,%eax
jge    12b0 <main+0x130>
lea    0xd91(%rip),%rdi
call   1090 <perror@plt>
lea    0xd8c(%rip),%rdi
mov    $0x30,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
xor    %eax,%eax
call   1060 <geteuid@plt>
test   %rax,%rax
je     11b9 <main+0x29>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1284 <main+0xf4>
mov    0x2e28(%rip),%r14
mov    (%r14),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
js     128e <main+0xfe>
movl   $0x7,0x8(%rsp)
mov    (%r14),%edi
mov    %edi,0x10(%rsp)
lea    0xc(%rsp),%rdx
lea    0xe0c(%rip),%rsi
call   1090 <inet_pton@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
movq   $0x0,0x38(%rsp)
mov    $0xf7fe,%edi
call   1040 <htons@plt>
mov    %rax,0x30(%rsp)
movq   $0x0,0x28(%rsp)
mov    $0x1,%edi
call   1040 <htons@plt>
mov    %rax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x18(%rsp),%rsi
lea    0x8(%rsp),%r8
mov    %ebx,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
lea    0xda4(%rip),%rdi
mov    $0x30,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd6b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1284 <main+0xf4>

LLVM IR (-O0):
%struct.icmp = type { i64, i8*, i64, i8*, i64, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [41 x i8] c"\0A----\0AError 1: Root yourself\0AExiting...\0A\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@.str.1 = [11 x i8] c"Icmp error\00"
@.str.2 = [8 x i8] c"8.8.8.8\00"
@ICMP_ECHO = global i32 0
@.str.3 = [7 x i8] c"sendto\00"
@.str.4 = [4 x i8] c"\0A%u\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.icmp
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 (...) @geteuid()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_RAW
%18 = load i32, i32* @IPPROTO_ICMP
%19 = call i32 @socket(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %8
store i32 %23, i32* %3
br label %51
24: ; preds = %15
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 7, i32* %25
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%30 = call i32 @inet_pton(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %29)
%31 = load i32, i32* @ICMP_ECHO
%32 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 5
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 4
store i64 0, i64* %33
%34 = call i8* @htons(i32 63486)
%35 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 3
store i8* %34, i8** %35
%36 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 2
store i64 0, i64* %36
%37 = call i8* @htons(i32 1)
%38 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 1
store i8* %37, i8** %38
%39 = getelementptr inbounds %struct.icmp, %struct.icmp* %9, i32 0, i32 0
store i64 0, i64* %39
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%43 = call i32 @sendto(i32 %41, %struct.icmp* %9, i32 4, i32 0, %struct.sockaddr* %42, i32 12)
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %47
45: ; preds = %24
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %24
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 48)
%49 = load i32, i32* %8
%50 = call i32 @close(i32 %49)
store i32 0, i32* %3
br label %51
51: ; preds = %47, %21, %13
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.icmp = type { i64, i8*, i64, i8*, i64, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_ICMP = global i32 0
@.str.1 = [11 x i8] c"Icmp error\00"
@.str.2 = [8 x i8] c"8.8.8.8\00"
@ICMP_ECHO = global i32 0
@.str.4 = [4 x i8] c"\0A%u\00"
@str = [40 x i8] c"\0A----\0AError 1: Root yourself\0AExiting...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.icmp
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.icmp* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = tail call i64 (...) @geteuid()
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %38
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_RAW
%14 = load i32, i32* @IPPROTO_ICMP
%15 = tail call i32 @socket(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %38
19: ; preds = %11
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 7, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%24 = call i32 @inet_pton(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %23)
%25 = load i32, i32* @ICMP_ECHO
%26 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 5
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 4
store i64 0, i64* %27
%28 = call i8* @htons(i32 63486)
%29 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 3
store i8* %28, i8** %29
%30 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 2
store i64 0, i64* %30
%31 = call i8* @htons(i32 1)
%32 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 1
store i8* %31, i8** %32
%33 = getelementptr inbounds %struct.icmp, %struct.icmp* %3, i64 0, i32 0
store i64 0, i64* %33
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i32 @sendto(i32 %15, %struct.icmp* %3, i32 4, i32 0, %struct.sockaddr* %34, i32 12)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 48)
%37 = call i32 @close(i32 %15)
br label %38
38: ; preds = %19, %17, %9
%39 = phi i32 [ -1, %9 ], [ %15, %17 ], [ 0, %19 ]
ret i32 %39
}