#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  int clientSocket = 0, portNumber = 9999, numberOfBytes = 0;
  char buffer[1024];
  struct sockaddr_in serverAddress;
  socklen_t address_size;
  clientSocket = socket(PF_INET, SOCK_DGRAM, 0);
  serverAddress.sin_family = AF_INET;
  serverAddress.sin_port = htons(portNumber);
  serverAddress.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddress.sin_zero, '\0', sizeof serverAddress.sin_zero);
  address_size = sizeof serverAddress;
  while (1) {
    printf("Type a sentence to send to server:\n");
    fgets(buffer, 1024, stdin);
    if (strcmp(buffer, "exit\n\0") == 0 || strcmp(buffer, "Exit\n\0") == 0) {
      break;
    }
    printf("You typed: %s", buffer);
    numberOfBytes = strlen(buffer) + 1;
    sendto(clientSocket, buffer, numberOfBytes, 0,
           (struct sockaddr *)&serverAddress, address_size);
    numberOfBytes = recvfrom(clientSocket, buffer, 1024, 0, NULL, NULL);
    printf("Received from server: %s\n", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x270f,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x428(%rbp)
lea    0xdf2(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x430(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x10,-0x434(%rbp)
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1297 <main+0xf7>
lea    -0x420(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    129c <main+0xfc>
jmp    1320 <main+0x180>
lea    -0x420(%rbp),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x430(%rbp),%r8
mov    -0x434(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10b0 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x420(%rbp),%rsi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1235 <main+0x95>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xe02(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     130f <main+0x15f>
lea    0x10(%rsp),%rbx
mov    %rsp,%r12
lea    0xdb7(%rip),%r13
lea    0xdca(%rip),%r15
lea    0xde6(%rip),%r14
nop
mov    %rbx,%rdi
lea    0xde2(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     130f <main+0x15f>
lea    0xd7b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0x10,%r9d
call   1080 <sendto@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <recvfrom@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <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

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [36 x i8] c"Type a sentence to send to server:\0A\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"exit\0A\00\00"
@.str.3 = [7 x i8] c"Exit\0A\00\00"
@.str.4 = [14 x i8] c"You typed: %s\00"
@.str.5 = [26 x i8] c"Received from server: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 9999, i32* %7
store i32 0, i32* %8
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* %7
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memset(i32 %24, i8 signext 0, i32 4)
store i32 16, i32* %11
br label %26
26: ; preds = %2, %39
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %28, i32 1024, i32 %29)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %26
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %26
br label %56
39: ; preds = %34
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
%45 = load i32, i32* %6
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* %8
%48 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%49 = load i32, i32* %11
%50 = call i32 @sendto(i32 %45, i8* %46, i32 %47, i32 0, %struct.sockaddr* %48, i32 %49)
%51 = load i32, i32* %6
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%53 = call i32 @recvfrom(i32 %51, i8* %52, i32 1024, i32 0, i32* null, i32* null)
store i32 %53, i32* %8
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %26
56: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@stdin = global i32 0
@.str.2 = [7 x i8] c"exit\0A\00\00"
@.str.3 = [7 x i8] c"Exit\0A\00\00"
@.str.4 = [14 x i8] c"You typed: %s\00"
@.str.5 = [26 x i8] c"Received from server: %s\0A\00"
@str = [35 x i8] c"Type a sentence to send to server:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @PF_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* %4, i64 0, i32 3
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 9999)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %5, i32 1024, i32 %18)
%20 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %39, label %22
22: ; preds = %2
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %24
24: ; preds = %22, %27
%25 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%29 = call i32 @strlen(i8* %5)
%30 = add nsw i32 %29, 1
%31 = call i32 @sendto(i32 %9, i8* %5, i32 %30, i32 0, %struct.sockaddr* %23, i32 16)
%32 = call i32 @recvfrom(i32 %9, i8* %5, i32 1024, i32 0, i32* null, i32* null)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %5, i32 1024, i32 %35)
%37 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %24
39: ; preds = %24, %27, %2
ret i32 0
}