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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
struct protoent *getprotobyname(char *);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void init(char *addr, struct sockaddr_in *dest, int *sock) {
  struct hostent *he;
  struct protoent *protoe;
  int proto, s;
  if (!(inet_aton(addr, &dest->sin_addr))) {
    if ((he = gethostbyname(addr)) == NULL) {
      fprintf(stderr, "ERR: unknown host '%s'!\n", addr);
      exit(1);
    }
    memcpy(&dest->sin_addr, he->h_addr, he->h_length);
  }
  dest->sin_family = AF_INET;
  protoe = getprotobyname("icmp");
  if (protoe)
    proto = protoe->p_proto;
  else
    proto = 1;
  s = socket(AF_INET, SOCK_RAW, proto);
  if (s < 0) {
    fprintf(stderr, "ERR: unable to make icmp socket! %s\n", strerror(errno));
    exit(1);
  }
  *sock = s;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
call   1060 <inet_aton@plt>
cmp    $0x0,%eax
jne    1202 <init+0x82>
mov    -0x8(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11e8 <init+0x68>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe27(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe01(%rip),%rdi
call   1070 <getprotobyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123a <init+0xba>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1241 <init+0xc1>
movl   $0x1,-0x2c(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
call   10a0 <socket@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    129e <init+0x11e>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd8f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x4(%rsi),%r12
mov    %r12,%rsi
call   1060 <inet_aton@plt>
test   %eax,%eax
jne    11bb <init+0x3b>
mov    %r15,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     122a <init+0xaa>
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r12,%rdi
call   1050 <memcpy@plt>
mov    0x2e26(%rip),%r15
mov    (%r15),%eax
mov    %eax,(%rbx)
lea    0xe4b(%rip),%rdi
call   1070 <getprotobyname@plt>
test   %rax,%rax
je     11dc <init+0x5c>
mov    (%rax),%edx
jmp    11e1 <init+0x61>
mov    $0x1,%edx
mov    (%r15),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
call   10a0 <socket@plt>
test   %eax,%eax
js     1205 <init+0x85>
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%ebx
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdfb(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    123d <init+0xbd>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.protoent = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERR: unknown host '%s'!\0A\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"icmp\00"
@SOCK_RAW = global i32 0
@.str.2 = [37 x i8] c"ERR: unable to make icmp socket! %s\0A\00"
@errno = global i32 0
define void @init(i8* %0, %struct.sockaddr_in* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32*
%7 = alloca %struct.hostent*
%8 = alloca %struct.protoent*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i32* %2, i32** %6
%11 = load i8*, i8** %4
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%14 = call i32 @inet_aton(i8* %11, i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call %struct.hostent* @gethostbyname(i8* %17)
store %struct.hostent* %18, %struct.hostent** %7
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %26, i32 0, i32 1
%28 = load %struct.hostent*, %struct.hostent** %7
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.hostent*, %struct.hostent** %7
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @memcpy(i32* %27, i32 %30, i32 %33)
br label %35
35: ; preds = %25, %3
%36 = load i32, i32* @AF_INET
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store %struct.protoent* %39, %struct.protoent** %8
%40 = load %struct.protoent*, %struct.protoent** %8
%41 = icmp ne %struct.protoent* %40, null
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load %struct.protoent*, %struct.protoent** %8
%44 = getelementptr inbounds %struct.protoent, %struct.protoent* %43, i32 0, i32 0
%45 = load i32, i32* %44
store i32 %45, i32* %9
br label %47
46: ; preds = %35
store i32 1, i32* %9
br label %47
47: ; preds = %46, %42
%48 = load i32, i32* @AF_INET
%49 = load i32, i32* @SOCK_RAW
%50 = load i32, i32* %9
%51 = call i32 @socket(i32 %48, i32 %49, i32 %50)
store i32 %51, i32* %10
%52 = load i32, i32* %10
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %47
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %47
%61 = load i32, i32* %10
%62 = load i32*, i32** %6
store i32 %61, i32* %62
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.protoent = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERR: unknown host '%s'!\0A\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"icmp\00"
@SOCK_RAW = global i32 0
@.str.2 = [37 x i8] c"ERR: unable to make icmp socket! %s\0A\00"
@errno = global i32 0
define void @init(i8* %0, %struct.sockaddr_in* %1, i32* nocapture writeonly %2) {
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
%5 = tail call i32 @inet_aton(i8* %0, i32* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = tail call %struct.hostent* @gethostbyname(i8* %0)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @memcpy(i32* %4, i32 %16, i32 %18)
br label %20
20: ; preds = %14, %3
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %21, i32* %22
%23 = tail call %struct.protoent* @getprotobyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq %struct.protoent* %23, null
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = getelementptr inbounds %struct.protoent, %struct.protoent* %23, i64 0, i32 0
%27 = load i32, i32* %26
br label %28
28: ; preds = %20, %25
%29 = phi i32 [ %27, %25 ], [ 1, %20 ]
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_RAW
%32 = tail call i32 @socket(i32 %30, i32 %31, i32 %29)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %28
store i32 %32, i32* %2
ret void
}