#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
scalar_t__ gethostbyname(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main() {
  int sock;
  struct sockaddr_in server_addr;
  struct hostent *host;
  char send_data[1024];
  host = (struct hostent *)gethostbyname((char *)"127.0.0.1");
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  }
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(5000);
  server_addr.sin_addr = *((struct in_addr *)host->h_addr);
  bzero(&(server_addr.sin_zero), 8);
  while (1) {
    printf("Type Something (q or Q to quit):");
    gets(send_data);
    if ((strcmp(send_data, "q") == 0) || strcmp(send_data, "Q") == 0)
      break;
    else
      sendto(sock, send_data, strlen(send_data), 0,
             (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11dc <main+0x4c>
jmp    11dc <main+0x4c>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1388,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
call   1090 <gets@plt>
lea    -0x420(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1261 <main+0xd1>
lea    -0x420(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1266 <main+0xd6>
jmp    12ae <main+0x11e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1060 <sendto@plt>
jmp    120f <main+0x7f>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe58(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,%rbx
mov    0x2e31(%rip),%r14
mov    (%r14),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    $0x1388,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     129f <main+0x10f>
lea    0xe02(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
lea    0xdd0(%rip),%r12
lea    0xdea(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     129f <main+0x10f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1060 <sendto@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1250 <main+0xc0>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [33 x i8] c"Type Something (q or Q to quit):\00"
@.str.2 = [2 x i8] c"q\00"
@.str.3 = [2 x i8] c"Q\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.hostent*
%5 = alloca [1024 x i8]
store i32 0, i32* %1
%6 = call i64 @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = inttoptr i64 %6 to %struct.hostent*
store %struct.hostent* %7, %struct.hostent** %4
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %0
br label %13
13: ; preds = %12, %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 3
store i32 %14, i32* %15
%16 = call i32 @htons(i32 5000)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%19 = load %struct.hostent*, %struct.hostent** %4
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to %struct.in_addr*
%23 = bitcast %struct.in_addr* %18 to i8*
%24 = bitcast %struct.in_addr* %22 to i8*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%26 = call i32 @bzero(i32* %25, i32 8)
br label %27
27: ; preds = %13, %46
%28 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%30 = call i32 @gets(i8* %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %27
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %27
br label %47
39: ; preds = %34
%40 = load i32, i32* %2
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%45 = call i32 @sendto(i32 %40, i8* %41, i32 %43, i32 0, %struct.sockaddr* %44, i32 4)
br label %46
46: ; preds = %39
br label %27
47: ; preds = %38
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [33 x i8] c"Type Something (q or Q to quit):\00"
@.str.2 = [2 x i8] c"q\00"
@.str.3 = [2 x i8] c"Q\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i64 @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = inttoptr i64 %5 to %struct.hostent*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 5000)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%15 = load i64, i64* %14
%16 = inttoptr i64 %15 to i32*
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%18 = load i32, i32* %16
store i32 %18, i32* %17
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%20 = call i32 @bzero(i32* %19, i32 8)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @gets(i8* %4)
%23 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %37, label %25
25: ; preds = %0
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %27
27: ; preds = %25, %30
%28 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = call i32 @strlen(i8* %4)
%32 = call i32 @sendto(i32 %9, i8* %4, i32 %31, i32 0, %struct.sockaddr* %26, i32 4)
%33 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @gets(i8* %4)
%35 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %27
37: ; preds = %27, %30, %0
ret i32 0
}