#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 dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fill_struct(char *, int, struct sockaddr_in *, int);
int get_sock_fd();
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  if (argc < 3) {
    printf("Usage %s server_hostname server_port\n", argv[0]);
    exit(0);
  }
  int portno = atoi(argv[2]);
  char *server_hostname = argv[1];
  struct sockaddr_in serv_addr;
  int sockfd, i, slen = sizeof(serv_addr);
  char buf[512];
  char message[512];
  sockfd = get_sock_fd();
  fill_struct(server_hostname, portno, &serv_addr, slen);
  while (1) {
    bzero(buf, 512);
    bzero(message, 512);
    printf("Enter message : ");
    fgets(message, 512, stdin);
    if (sendto(sockfd, message, strlen(message), 0,
               (struct sockaddr *)&serv_addr, slen) == -1) {
      error("sendto()");
    }
    memset(buf, '\0', 512);
    if (recvfrom(sockfd, buf, 512, 0, (struct sockaddr *)&serv_addr, &slen) ==
        -1) {
      error("recvfrom()");
    }
    puts(buf);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    120f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x4,-0x34(%rbp)
mov    $0x0,%al
call   1030 <get_sock_fd@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%ecx
lea    -0x28(%rbp),%rdx
call   10b0 <fill_struct@plt>
lea    -0x240(%rbp),%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
lea    -0x440(%rbp),%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x440(%rbp),%rdi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1090 <fgets@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x440(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
mov    -0x34(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12ef <main+0x11f>
lea    0xd4d(%rip),%rdi
call   10c0 <error@plt>
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x2c(%rbp),%edi
lea    -0x240(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1335 <main+0x165>
lea    0xd10(%rip),%rdi
call   10c0 <error@plt>
lea    -0x240(%rbp),%rdi
call   1040 <puts@plt>
jmp    124f <main+0x7f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    12f3 <main+0x123>
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rbx
movl   $0x4,0x4(%rsp)
xor    %eax,%eax
call   1030 <get_sock_fd@plt>
mov    %eax,%r15d
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    $0x4,%ecx
call   10b0 <fill_struct@plt>
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rbp
lea    0xded(%rip),%r12
lea    0x4(%rsp),%r13
jmp    1248 <main+0x78>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
mov    %rbp,%rdi
mov    $0x200,%esi
call   10d0 <bzero@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
mov    $0x200,%esi
call   1090 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    0x4(%rsp),%r9d
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12b2 <main+0xe2>
lea    0xd8a(%rip),%rdi
call   10c0 <error@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
jne    1240 <main+0x70>
lea    0xd57(%rip),%rdi
call   10c0 <error@plt>
jmp    1240 <main+0x70>
mov    (%rbx),%rsi
lea    0xd03(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [38 x i8] c"Usage %s server_hostname server_port\0A\00"
@.str.1 = [17 x i8] c"Enter message : \00"
@stdin = global i32 0
@.str.2 = [9 x i8] c"sendto()\00"
@.str.3 = [11 x i8] c"recvfrom()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [512 x i8]
%13 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %7
store i32 4, i32* %11
%30 = call i32 (...) @get_sock_fd()
store i32 %30, i32* %9
%31 = load i8*, i8** %7
%32 = load i32, i32* %6
%33 = load i32, i32* %11
%34 = call i32 @fill_struct(i8* %31, i32 %32, %struct.sockaddr_in* %8, i32 %33)
br label %35
35: ; preds = %22, %64
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%37 = call i32 @bzero(i8* %36, i32 512)
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%39 = call i32 @bzero(i8* %38, i32 512)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 512, i32 %42)
%44 = load i32, i32* %9
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%49 = load i32, i32* %11
%50 = call i32 @sendto(i32 %44, i8* %45, i32 %47, i32 0, %struct.sockaddr* %48, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %35
%53 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %35
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%56 = call i32 @memset(i8* %55, i8 signext 0, i32 512)
%57 = load i32, i32* %9
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%59 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%60 = call i32 @recvfrom(i32 %57, i8* %58, i32 512, i32 0, %struct.sockaddr* %59, i32* %11)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %54
%63 = call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %62, %54
%65 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%66 = call i32 @puts(i8* %65)
br label %35
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [38 x i8] c"Usage %s server_hostname server_port\0A\00"
@.str.1 = [17 x i8] c"Enter message : \00"
@stdin = global i32 0
@.str.2 = [9 x i8] c"sendto()\00"
@.str.3 = [11 x i8] c"recvfrom()\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = bitcast %struct.sockaddr_in* %3 to i8*
%19 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%22 = tail call i32 (...) @get_sock_fd()
%23 = call i32 @fill_struct(i8* %17, i32 %15, %struct.sockaddr_in* %3, i32 4)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %25
25: ; preds = %43, %12
%26 = call i32 @bzero(i8* %20, i32 512)
%27 = call i32 @bzero(i8* %21, i32 512)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %21, i32 512, i32 %29)
%31 = call i32 @strlen(i8* %21)
%32 = load i32, i32* %4
%33 = call i32 @sendto(i32 %22, i8* %21, i32 %31, i32 0, %struct.sockaddr* %24, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 @error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %25
%38 = call i32 @memset(i8* %20, i8 signext 0, i32 512)
%39 = call i32 @recvfrom(i32 %22, i8* %20, i32 512, i32 0, %struct.sockaddr* %24, i32* %4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @error(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = call i32 @puts(i8* %20)
br label %25
}