#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 */
typedef int /*<<< orphan*/ targetinfo;
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ memset(struct addrinfo **, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
struct addrinfo *prepare_addrinfo(char const *, char const *,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int sendto(int, char const *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char const *argv[]) {
  if (argc != 4) {
    fprintf(stderr,
            "Usage: showip <target_hostname> <target_port> <message_string>\n");
    return 1;
  }
  struct addrinfo *targetinfo;
  int sockfd;
  int send_nbytes, send_count;
  memset(&targetinfo, 0, sizeof(targetinfo));
  targetinfo = prepare_addrinfo(argv[1], argv[2], AF_INET, SOCK_DGRAM);
  sockfd = socket(targetinfo->ai_family, targetinfo->ai_socktype,
                  targetinfo->ai_protocol);
  if (sockfd == -1) {
    perror("\tsocket");
    return 2;
  }
  printf("\tSocket created.\n");
  for (send_count = 0; send_count < 5; send_count++) {
    if ((send_nbytes = sendto(sockfd, argv[3], strlen(argv[3]), 0,
                              targetinfo->ai_addr, targetinfo->ai_addrlen)) ==
        -1) {
      perror("\tsendto");
      return 3;
    }
  }
  freeaddrinfo(targetinfo);
  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)
cmpl   $0x4,-0x8(%rbp)
je     11d1 <main+0x41>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ed <main+0x15d>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    0x2ddf(%rip),%rax
mov    (%rax),%ecx
call   1080 <prepare_addrinfo@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    124b <main+0xbb>
lea    0xe06(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ed <main+0x15d>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    12dd <main+0x14d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    12ca <main+0x13a>
lea    0xda1(%rip),%rdi
call   1090 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    12ed <main+0x15d>
jmp    12cf <main+0x13f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125e <main+0xce>
mov    -0x18(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x4,%edi
jne    12f5 <main+0x165>
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
call   1080 <prepare_addrinfo@plt>
mov    %rax,0x8(%rsp)
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     132d <main+0x19d>
mov    %eax,%r14d
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     131a <main+0x18a>
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     131a <main+0x18a>
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     131a <main+0x18a>
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     131a <main+0x18a>
mov    0x18(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0x8(%rsp),%rcx
mov    (%rcx),%r9d
mov    0x4(%rcx),%r8d
xor    %ebx,%ebx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
je     131a <main+0x18a>
mov    0x8(%rsp),%rdi
call   10a0 <freeaddrinfo@plt>
jmp    130f <main+0x17f>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd27(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%ebx
jmp    130f <main+0x17f>
lea    0xd0c(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%ebx
jmp    130f <main+0x17f>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [64 x i8] c"Usage: showip <target_hostname> <target_port> <message_string>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [8 x i8] c"\09socket\00"
@.str.2 = [18 x i8] c"\09Socket created.\0A\00"
@.str.3 = [8 x i8] c"\09sendto\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %71
15: ; preds = %2
%16 = call i32 @memset(%struct.addrinfo** %6, i32 0, i32 8)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call %struct.addrinfo* @prepare_addrinfo(i8* %19, i8* %22, i32 %23, i32 %24)
store %struct.addrinfo* %25, %struct.addrinfo** %6
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i32 0, i32 4
%28 = load i32, i32* %27
%29 = load %struct.addrinfo*, %struct.addrinfo** %6
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i32 0, i32 3
%31 = load i32, i32* %30
%32 = load %struct.addrinfo*, %struct.addrinfo** %6
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = call i32 @socket(i32 %28, i32 %31, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %15
%39 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %71
40: ; preds = %15
%41 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %42
42: ; preds = %65, %40
%43 = load i32, i32* %9
%44 = icmp slt i32 %43, 5
br i1 %44, label %45, label %68
45: ; preds = %42
%46 = load i32, i32* %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i32 @strlen(i8* %52)
%54 = load %struct.addrinfo*, %struct.addrinfo** %6
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 1
%56 = load i32, i32* %55
%57 = load %struct.addrinfo*, %struct.addrinfo** %6
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 0
%59 = load i32, i32* %58
%60 = call i32 @sendto(i32 %46, i8* %49, i32 %53, i32 0, i32 %56, i32 %59)
store i32 %60, i32* %8
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %45
%63 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %71
64: ; preds = %45
br label %65
65: ; preds = %64
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %42
68: ; preds = %42
%69 = load %struct.addrinfo*, %struct.addrinfo** %6
%70 = call i32 @freeaddrinfo(%struct.addrinfo* %69)
store i32 0, i32* %3
br label %71
71: ; preds = %68, %62, %38, %12
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [64 x i8] c"Usage: showip <target_hostname> <target_port> <message_string>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [8 x i8] c"\09socket\00"
@.str.3 = [8 x i8] c"\09sendto\00"
@str = [17 x i8] c"\09Socket created.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo*
%4 = icmp eq i32 %0, 4
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
br label %87
8: ; preds = %2
%9 = bitcast %struct.addrinfo** %3 to i8*
%10 = call i32 @memset(%struct.addrinfo** %3, i32 0, i32 8)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call %struct.addrinfo* @prepare_addrinfo(i8* %12, i8* %14, i32 %15, i32 %16)
store %struct.addrinfo* %17, %struct.addrinfo** %3
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @socket(i32 %19, i32 %21, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %8
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %85
28: ; preds = %8
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = load %struct.addrinfo*, %struct.addrinfo** %3
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 1
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i64 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @sendto(i32 %24, i8* %31, i32 %32, i32 0, i32 %35, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %83, label %40
40: ; preds = %28
%41 = load i8*, i8** %30
%42 = call i32 @strlen(i8* %41)
%43 = load %struct.addrinfo*, %struct.addrinfo** %3
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @sendto(i32 %24, i8* %41, i32 %42, i32 0, i32 %45, i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %83, label %50
50: ; preds = %40
%51 = load i8*, i8** %30
%52 = call i32 @strlen(i8* %51)
%53 = load %struct.addrinfo*, %struct.addrinfo** %3
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i64 0, i32 1
%55 = load i32, i32* %54
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i64 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @sendto(i32 %24, i8* %51, i32 %52, i32 0, i32 %55, i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %83, label %60
60: ; preds = %50
%61 = load i8*, i8** %30
%62 = call i32 @strlen(i8* %61)
%63 = load %struct.addrinfo*, %struct.addrinfo** %3
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i64 0, i32 1
%65 = load i32, i32* %64
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i64 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @sendto(i32 %24, i8* %61, i32 %62, i32 0, i32 %65, i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %83, label %70
70: ; preds = %60
%71 = load i8*, i8** %30
%72 = call i32 @strlen(i8* %71)
%73 = load %struct.addrinfo*, %struct.addrinfo** %3
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i64 0, i32 1
%75 = load i32, i32* %74
%76 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i64 0, i32 0
%77 = load i32, i32* %76
%78 = call i32 @sendto(i32 %24, i8* %71, i32 %72, i32 0, i32 %75, i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %83, label %80
80: ; preds = %70
%81 = load %struct.addrinfo*, %struct.addrinfo** %3
%82 = call i32 @freeaddrinfo(%struct.addrinfo* %81)
br label %85
83: ; preds = %70, %60, %50, %40, %28
%84 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %85
85: ; preds = %80, %83, %26
%86 = phi i32 [ 2, %26 ], [ 3, %83 ], [ 0, %80 ]
br label %87
87: ; preds = %85, %5
%88 = phi i32 [ 1, %5 ], [ %86, %85 ]
ret i32 %88
}