#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);
int /*<<< orphan*/ exit(int);
scalar_t__ gethostbyname(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int, 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(27, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(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    0xe37(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    $0x1b,%edi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1209 <main+0x59>
lea    0xe10(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dd8(%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   10b0 <bzero@plt>
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
call   1090 <gets@plt>
lea    -0x420(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     128e <main+0xde>
lea    -0x420(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1293 <main+0xe3>
jmp    12db <main+0x12b>
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    123c <main+0x8c>
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    0xe38(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,%rbx
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    $0x1b,%edi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12d3 <main+0x123>
mov    %eax,%ebp
mov    0x2df1(%rip),%rax
mov    (%rax),%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   10b0 <bzero@plt>
lea    0xde9(%rip),%rdi
call   1050 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
lea    0xdf1(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12bf <main+0x10f>
lea    0xddf(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
lea    0xdad(%rip),%r12
lea    0xdc7(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12bf <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    1270 <main+0xc0>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd30(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

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

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