#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ remote_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd;
  int retval;
  struct sockaddr_in remote_addr;
  socklen_t addr_len;
  char buff[256] = "Laboratorium PUS.";
  if (argc != 3) {
    fprintf(stderr, "Invocation: %s <IPv4 ADDRESS> <PORT>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sockfd = socket(PF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1) {
    perror("socket()");
    exit(EXIT_FAILURE);
  }
  memset(&remote_addr, 0, sizeof(remote_addr));
  remote_addr.sin_family = AF_INET;
  retval = inet_pton(AF_INET, argv[1], &remote_addr.sin_addr);
  if (retval == 0) {
    fprintf(stderr, "inet_pton(): invalid network address!\n");
    exit(EXIT_FAILURE);
  } else if (retval == -1) {
    perror("inet_pton()");
    exit(EXIT_FAILURE);
  }
  remote_addr.sin_port = htons(atoi(argv[2]));
  addr_len = sizeof(remote_addr);
  fprintf(stdout, "Sending message to %s.\n", argv[1]);
  retval = sendto(sockfd, buff, strlen(buff), 0,
                  (struct sockaddr *)&remote_addr, addr_len);
  if (retval == -1) {
    perror("sendto()");
    exit(EXIT_FAILURE);
  }
  close(sockfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x130(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x100,%edx
call   1090 <memcpy@plt>
cmpl   $0x3,-0x8(%rbp)
je     1227 <main+0x67>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xeee(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1267 <main+0xa7>
lea    0xed2(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
call   10a0 <inet_pton@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    12d3 <main+0x113>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    12f7 <main+0x137>
lea    0xe72(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    12fc <main+0x13c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x13c(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13a1 <main+0x1e1>
lea    0xdec(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2c00(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe2b(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x100,%edx
call   1090 <memcpy@plt>
cmp    $0x3,%ebp
jne    1213 <main+0x53>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1232 <main+0x72>
lea    0xf18(%rip),%rdi
jmp    12e7 <main+0x127>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xeda(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12ec <main+0x12c>
mov    %eax,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdx
call   10a0 <inet_pton@plt>
cmp    $0xffffffff,%eax
je     1280 <main+0xc0>
test   %eax,%eax
jne    1289 <main+0xc9>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12ec <main+0x12c>
lea    0xecf(%rip),%rdi
jmp    12e7 <main+0x127>
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12fa <main+0x13a>
lea    0xe93(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buff = [256 x i8] c"Laboratorium PUS.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [38 x i8] c"Invocation: %s <IPv4 ADDRESS> <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@.str.2 = [39 x i8] c"inet_pton(): invalid network address!\0A\00"
@.str.3 = [12 x i8] c"inet_pton()\00"
@stdout = global i32 0
@.str.4 = [24 x i8] c"Sending message to %s.\0A\00"
@.str.5 = [9 x i8] c"sendto()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [256 x i8]* %10 to i8*
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @AF_INET
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%41 = call i32 @inet_pton(i32 %36, i8* %39, i32* %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %32
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %32
%50 = load i32, i32* %7
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %49
br label %57
57: ; preds = %56
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
%60 = load i8*, i8** %59
%61 = call i32 @atoi(i8* %60)
%62 = call i32 @htons(i32 %61)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %62, i32* %63
store i32 12, i32* %9
%64 = load i32, i32* @stdout
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %67)
%69 = load i32, i32* %6
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%72 = call i32 @strlen(i8* %71)
%73 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%74 = load i32, i32* %9
%75 = call i32 @sendto(i32 %69, i8* %70, i32 %72, i32 0, %struct.sockaddr* %73, i32 %74)
store i32 %75, i32* %7
%76 = load i32, i32* %7
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %82
78: ; preds = %57
%79 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %57
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* @EXIT_SUCCESS
%86 = call i32 @exit(i32 %85)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.buff = [256 x i8] c"Laboratorium PUS.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [38 x i8] c"Invocation: %s <IPv4 ADDRESS> <PORT>\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@AF_INET = global i32 0
@.str.2 = [39 x i8] c"inet_pton(): invalid network address!\0A\00"
@.str.3 = [12 x i8] c"inet_pton()\00"
@stdout = global i32 0
@.str.4 = [24 x i8] c"Sending message to %s.\0A\00"
@.str.5 = [9 x i8] c"sendto()\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%30 = call i32 @inet_pton(i32 %25, i8* %28, i32* %29)
switch i32 %30, label %40 [
i32 0, label %31
i32 -1, label %36
]
31: ; preds = %23
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %23
%37 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %23
%41 = getelementptr inbounds i8*, i8** %1, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* @stdout
%47 = load i8*, i8** %27
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = call i32 @strlen(i8* %6)
%50 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%51 = call i32 @sendto(i32 %17, i8* %6, i32 %49, i32 0, %struct.sockaddr* %50, i32 12)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %40
%54 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %40
%58 = call i32 @close(i32 %17)
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
}