#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 protoent {
  int /*<<< orphan*/ p_proto;
};
struct hostent {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getchar();
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ getutid();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct hostent *host;
  struct protoent *protocol;
  unsigned long inaddr = 0l;
  int waittime = 100;
  int size = 50 * 1024;
  if (argc < 2) {
    printf("Usage:%s hostname/IP address\n", argv[0]);
    exit(1);
  }
  if ((protocol = getprotobyname("icmp")) == NULL) {
    perror("getprotobyname call error");
    exit(1);
  }
  int sockfd;
  if ((sockfd = socket(AF_INET, SOCK_RAW, protocol->p_proto)) < 0) {
    perror("socket error");
    exit(1);
  }
  setuid(getutid());
  initscr();
  printw("Hello");
  refresh();
  getchar();
  endwin();
  printf("APP:\t%s\nVERSION:\t%s\n", "pfans", "0.1");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x64,-0x2c(%rbp)
movl   $0xc800,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1215 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe02(%rip),%rdi
call   1070 <getprotobyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1245 <main+0x85>
lea    0xded(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1284 <main+0xc4>
lea    0xdc8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10d0 <getutid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
mov    $0x0,%al
call   1040 <initscr@plt>
lea    0xdaa(%rip),%rdi
call   1060 <printw@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1090 <endwin@plt>
lea    0xd8f(%rip),%rdi
lea    0xd9d(%rip),%rsi
lea    0xd9c(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jle    1252 <main+0x92>
lea    0xe4d(%rip),%rdi
call   1070 <getprotobyname@plt>
test   %rax,%rax
je     126d <main+0xad>
mov    0x2e02(%rip),%rcx
mov    (%rcx),%edi
mov    0x2df1(%rip),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     1276 <main+0xb6>
xor    %eax,%eax
call   10d0 <getutid@plt>
mov    %eax,%edi
call   10c0 <setuid@plt>
xor    %eax,%eax
call   1040 <initscr@plt>
lea    0xe32(%rip),%rdi
call   1060 <printw@plt>
xor    %eax,%eax
call   1080 <refresh@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1090 <endwin@plt>
lea    0xe17(%rip),%rdi
lea    0xe25(%rip),%rsi
lea    0xe24(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    (%rsi),%rsi
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdaf(%rip),%rdi
jmp    127d <main+0xbd>
lea    0xdc0(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32 }
%struct.protoent = type { i32 }
@.str = [30 x i8] c"Usage:%s hostname/IP address\0A\00"
@.str.1 = [5 x i8] c"icmp\00"
@.str.2 = [26 x i8] c"getprotobyname call error\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str.3 = [13 x i8] c"socket error\00"
@.str.4 = [6 x i8] c"Hello\00"
@.str.5 = [21 x i8] c"APP:\09%s\0AVERSION:\09%s\0A\00"
@.str.6 = [6 x i8] c"pfans\00"
@.str.7 = [4 x i8] c"0.1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.protoent*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %8
store i32 100, i32* %9
store i32 51200, i32* %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.protoent* %21, %struct.protoent** %7
%22 = icmp eq %struct.protoent* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_RAW
%29 = load %struct.protoent*, %struct.protoent** %7
%30 = getelementptr inbounds %struct.protoent, %struct.protoent* %29, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @socket(i32 %27, i32 %28, i32 %31)
store i32 %32, i32* %11
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
%38 = call i32 (...) @getutid()
%39 = call i32 @setuid(i32 %38)
%40 = call i32 (...) @initscr()
%41 = call i32 @printw(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (...) @refresh()
%43 = call i32 (...) @getchar()
%44 = call i32 (...) @endwin()
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
%struct.protoent = type { i32 }
@.str = [30 x i8] c"Usage:%s hostname/IP address\0A\00"
@.str.1 = [5 x i8] c"icmp\00"
@.str.2 = [26 x i8] c"getprotobyname call error\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@.str.3 = [13 x i8] c"socket error\00"
@.str.4 = [6 x i8] c"Hello\00"
@.str.5 = [21 x i8] c"APP:\09%s\0AVERSION:\09%s\0A\00"
@.str.6 = [6 x i8] c"pfans\00"
@.str.7 = [4 x i8] c"0.1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq %struct.protoent* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_RAW
%17 = getelementptr inbounds %struct.protoent, %struct.protoent* %9, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @socket(i32 %15, i32 %16, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = tail call i32 (...) @getutid()
%26 = tail call i32 @setuid(i32 %25)
%27 = tail call i32 (...) @initscr()
%28 = tail call i32 @printw(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 (...) @refresh()
%30 = tail call i32 (...) @getchar()
%31 = tail call i32 (...) @endwin()
%32 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}