#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 addrinfo {
  int /*<<< orphan*/ ai_addr;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
struct addrinfo *createAddressInfo(char const *, char const *);
int createSocket(struct addrinfo *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/ *);
char *strerror(int /*<<< orphan*/);
int strtol(char *, char **, int);
int main(int argc, char **argv) {
  char *pEnd;
  char str[15];
  socklen_t fromlen;
  char buffer[512];
  const char *ipTx = argv[1];
  const char *ipRx = argv[2];
  const char *portTx = argv[3];
  const char *portRx = argv[4];
  const int rateTx = strtol(argv[5], &pEnd, 10);
  printf("Transmit IP: %s\n", ipTx);
  printf("Receive IP: %s\n", ipRx);
  printf("Transmit Port: %s\n", portTx);
  printf("Receive Port: %s\n", portRx);
  printf("Transport Rate: %ld\n", rateTx);
  struct addrinfo *addr = createAddressInfo(ipRx, portRx);
  int socket = createSocket(addr);
  int success =
      recvfrom(socket, buffer, sizeof(buffer), 0, addr->ai_addr, &fromlen);
  if (success == -1) {
    printf("Error: %s\n", strerror(errno));
    printf("Error occurred sending so now I am sad");
    return -1;
  }
  printf("%s\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x238(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x240(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x248(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x250(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x254(%rbp)
mov    -0x238(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x240(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x248(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x250(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x254(%rbp),%esi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x240(%rbp),%rdi
mov    -0x250(%rbp),%rsi
call   1050 <createAddressInfo@plt>
mov    %rax,-0x260(%rbp)
mov    -0x260(%rbp),%rdi
call   1030 <createSocket@plt>
mov    %eax,-0x264(%rbp)
mov    -0x264(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x260(%rbp),%rax
mov    (%rax),%r8d
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x2c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x268(%rbp)
cmpl   $0xffffffff,-0x268(%rbp)
jne    12d8 <main+0x178>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f4 <main+0x194>
lea    -0x230(%rbp),%rsi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%r13
mov    0x18(%rsi),%r12
mov    0x20(%rsi),%rbp
mov    0x28(%rsi),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%r15d
lea    0xe52(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe51(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <createAddressInfo@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <createSocket@plt>
mov    (%rbx),%r8d
lea    0x10(%rsp),%rsi
lea    0x4(%rsp),%r9
mov    %eax,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1080 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xd1>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
jmp    1274 <main+0x104>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe05(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32 }
@.str = [17 x i8] c"Transmit IP: %s\0A\00"
@.str.1 = [16 x i8] c"Receive IP: %s\0A\00"
@.str.2 = [19 x i8] c"Transmit Port: %s\0A\00"
@.str.3 = [18 x i8] c"Receive Port: %s\0A\00"
@.str.4 = [21 x i8] c"Transport Rate: %ld\0A\00"
@.str.5 = [11 x i8] c"Error: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"Error occurred sending so now I am sad\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [15 x i8]
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca %struct.addrinfo*
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %10
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %11
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
store i8* %26, i8** %12
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 4
%29 = load i8*, i8** %28
store i8* %29, i8** %13
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 5
%32 = load i8*, i8** %31
%33 = call i32 @strtol(i8* %32, i8** %6, i32 10)
store i32 %33, i32* %14
%34 = load i8*, i8** %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %11
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %12
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %13
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %14
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %11
%45 = load i8*, i8** %13
%46 = call %struct.addrinfo* @createAddressInfo(i8* %44, i8* %45)
store %struct.addrinfo* %46, %struct.addrinfo** %15
%47 = load %struct.addrinfo*, %struct.addrinfo** %15
%48 = call i32 @createSocket(%struct.addrinfo* %47)
store i32 %48, i32* %16
%49 = load i32, i32* %16
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%51 = load %struct.addrinfo*, %struct.addrinfo** %15
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @recvfrom(i32 %49, i8* %50, i32 512, i32 0, i32 %53, i32* %8)
store i32 %54, i32* %17
%55 = load i32, i32* %17
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %62
57: ; preds = %2
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %65
62: ; preds = %2
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %62, %57
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.addrinfo = type { i32 }
@.str = [17 x i8] c"Transmit IP: %s\0A\00"
@.str.1 = [16 x i8] c"Receive IP: %s\0A\00"
@.str.2 = [19 x i8] c"Transmit Port: %s\0A\00"
@.str.3 = [18 x i8] c"Receive Port: %s\0A\00"
@.str.4 = [21 x i8] c"Transport Rate: %ld\0A\00"
@.str.5 = [11 x i8] c"Error: %s\0A\00"
@errno = global i32 0
@.str.6 = [39 x i8] c"Error occurred sending so now I am sad\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = bitcast i8** %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %1, i64 4
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 5
%18 = load i8*, i8** %17
%19 = call i32 @strtol(i8* %18, i8** %3, i32 10)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%25 = tail call %struct.addrinfo* @createAddressInfo(i8* %12, i8* %16)
%26 = tail call i32 @createSocket(%struct.addrinfo* %25)
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %25, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @recvfrom(i32 %26, i8* %8, i32 512, i32 0, i32 %28, i32* %4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %2
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %38
36: ; preds = %2
%37 = call i32 @puts(i8* %8)
br label %38
38: ; preds = %36, %31
%39 = phi i32 [ -1, %31 ], [ 0, %36 ]
ret i32 %39
}