#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  struct hostent *hp;
  struct sockaddr_in servaddr;
  char my_message[1024] = {};
  char *host = argv[1];
  char *port = argv[2];
  int fd;
  if (argc != 3) {
    printf("Input ERROR - usage: %s serverip port\n", argv[0]);
    exit(1);
  }
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("cannot create socket\n");
    return 0;
  }
  memset((char *)&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(atoi(port));
  hp = gethostbyname(host);
  if (!hp) {
    fprintf(stderr, "could not obtain address of %s\n", host);
    return 0;
  }
  memcpy(&servaddr.sin_addr, hp->h_addr, hp->h_length);
  printf("Enter the message to be sent : ");
  gets(my_message);
  if (sendto(fd, my_message, strlen(my_message), 0,
             (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    perror("sendto failed");
    return 0;
  }
  printf("\nMessage Sent Successfully.! Check Server\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x440(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1243 <main+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x444(%rbp)
cmp    $0x0,%eax
jge    1283 <main+0xb3>
lea    0xdb5(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    139e <main+0x1ce>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x440(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x438(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12f8 <main+0x128>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
mov    -0x438(%rbp),%rdx
lea    0xd56(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    139e <main+0x1ce>
lea    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <memcpy@plt>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x430(%rbp),%rdi
call   10b0 <gets@plt>
mov    -0x444(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0x0,%rax
jge    1390 <main+0x1c0>
lea    0xcfe(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    139e <main+0x1ce>
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
cmp    $0x3,%ebx
jne    130f <main+0x12f>
mov    0x8(%rbp),%r15
mov    0x10(%rbp),%rbp
mov    0x2dcd(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12f3 <main+0x113>
mov    %eax,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    %rbp,%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %r15,%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
je     12cb <main+0xeb>
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10b0 <memcpy@plt>
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   10c0 <gets@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
test   %rax,%rax
js     1301 <main+0x121>
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
jmp    12e3 <main+0x103>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    %r15,%rdx
call   10a0 <fprintf@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2d(%rip),%rdi
call   10d0 <perror@plt>
jmp    12e3 <main+0x103>
lea    0xd75(%rip),%rdi
call   10d0 <perror@plt>
jmp    12e3 <main+0x103>
mov    0x0(%rbp),%rsi
lea    0xce6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Input ERROR - usage: %s serverip port\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"cannot create socket\0A\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"could not obtain address of %s\0A\00"
@.str.3 = [32 x i8] c"Enter the message to be sent : \00"
@.str.4 = [14 x i8] c"sendto failed\00"
@.str.5 = [43 x i8] c"\0AMessage Sent Successfully.! Check Server\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.hostent*
%7 = alloca %struct.sockaddr_in
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [1024 x i8]* %8 to i8*
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %9
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
store i8* %18, i8** %10
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %27
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_DGRAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %11
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %74
34: ; preds = %27
%35 = bitcast %struct.sockaddr_in* %7 to i8*
%36 = call i32 @memset(i8* %35, i32 0, i32 12)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %37, i32* %38
%39 = load i8*, i8** %10
%40 = call i32 @atoi(i8* %39)
%41 = call i32 @htons(i32 %40)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %41, i32* %42
%43 = load i8*, i8** %9
%44 = call %struct.hostent* @gethostbyname(i8* %43)
store %struct.hostent* %44, %struct.hostent** %6
%45 = load %struct.hostent*, %struct.hostent** %6
%46 = icmp ne %struct.hostent* %45, null
br i1 %46, label %51, label %47
47: ; preds = %34
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %9
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %49)
store i32 0, i32* %3
br label %74
51: ; preds = %34
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%53 = load %struct.hostent*, %struct.hostent** %6
%54 = getelementptr inbounds %struct.hostent, %struct.hostent* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = load %struct.hostent*, %struct.hostent** %6
%57 = getelementptr inbounds %struct.hostent, %struct.hostent* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @memcpy(i32* %52, i32 %55, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%62 = call i32 @gets(i8* %61)
%63 = load i32, i32* %11
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%68 = call i64 @sendto(i32 %63, i8* %64, i32 %66, i32 0, %struct.sockaddr* %67, i32 12)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %51
%71 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %74
72: ; preds = %51
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %70, %47, %32
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Input ERROR - usage: %s serverip port\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"cannot create socket\0A\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"could not obtain address of %s\0A\00"
@.str.3 = [32 x i8] c"Enter the message to be sent : \00"
@.str.4 = [14 x i8] c"sendto failed\00"
@str = [42 x i8] c"\0AMessage Sent Successfully.! Check Server\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %52
23: ; preds = %16
%24 = call i32 @memset(i8* %5, 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 = call i32 @atoi(i8* %10)
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %28, i32* %29
%30 = call %struct.hostent* @gethostbyname(i8* %8)
%31 = icmp eq %struct.hostent* %30, null
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %52
35: ; preds = %23
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 1
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @memcpy(i32* %36, i32 %38, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @gets(i8* %6)
%44 = call i32 @strlen(i8* %6)
%45 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%46 = call i64 @sendto(i32 %19, i8* %6, i32 %44, i32 0, %struct.sockaddr* %45, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %35
%49 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %52
50: ; preds = %35
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %52
52: ; preds = %50, %48, %32, %21
ret i32 0
}