#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_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
typedef int /*<<< orphan*/ dest;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect_to_socket(int, struct sockaddr_in);
int create_socket();
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ get_message(int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *const);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_message(int, char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *const argv[]) {
  int socket_client;
  struct sockaddr_in dest;
  char in_buf[256];
  char out_buf[256];
  bzero(in_buf, 256);
  bzero(out_buf, 256);
  socket_client = create_socket();
  bzero((char *)&dest, sizeof(dest));
  dest.sin_addr.s_addr = inet_addr(argv[1]);
  dest.sin_family = AF_INET;
  dest.sin_port = htons(4711);
  connect_to_socket(socket_client, dest);
  while (1) {
    printf("Message to server: ");
    bzero(out_buf, 256);
    fgets(out_buf, 256, stdin);
    if (strcmp(out_buf, "quit\n") == 0) {
      break;
    }
    printf("sending: %s\n", out_buf);
    send_message(socket_client, out_buf);
    printf("waiting for reply...\n");
    bzero(in_buf, 256);
    get_message(socket_client, in_buf);
    printf("server sayz: %s\n", in_buf);
  }
  close(socket_client);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
lea    -0x220(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    $0x0,%al
call   10c0 <create_socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1267,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,-0x230(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x228(%rbp)
mov    -0x230(%rbp),%rsi
mov    -0x228(%rbp),%edx
call   1040 <connect_to_socket@plt>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
lea    -0x220(%rbp),%rdi
mov    0x2d5e(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1090 <fgets@plt>
lea    -0x220(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    12b0 <main+0x100>
jmp    131c <main+0x16c>
lea    -0x220(%rbp),%rsi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
call   1070 <send_message@plt>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10d0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
call   1030 <get_message@plt>
lea    -0x120(%rbp),%rsi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1255 <main+0xa5>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%rbp
lea    0x110(%rsp),%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
xor    %eax,%eax
call   10d0 <create_socket@plt>
mov    %eax,%r12d
mov    %rsp,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x8(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,%ebp
mov    %eax,0x8(%rsp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    $0x1267,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    (%rsp),%rsi
mov    %r12d,%edi
mov    %ebp,%edx
call   1040 <connect_to_socket@plt>
lea    0xdb3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <fgets@plt>
lea    0xd96(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     134e <main+0x18e>
lea    0x10(%rsp),%rbx
lea    0x110(%rsp),%rbp
lea    0xd84(%rip),%r13
lea    0xd56(%rip),%r14
lea    0xd63(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd53(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1080 <send_message@plt>
lea    0xd55(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
call   1030 <get_message@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10e0 <bzero@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    12c0 <main+0x100>
mov    %r12d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@.str = [20 x i8] c"Message to server: \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"quit\0A\00"
@.str.2 = [13 x i8] c"sending: %s\0A\00"
@.str.3 = [22 x i8] c"waiting for reply...\0A\00"
@.str.4 = [17 x i8] c"server sayz: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca { i64, i32 }
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%12 = call i32 @bzero(i8* %11, i32 256)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 256)
%15 = call i32 (...) @create_socket()
store i32 %15, i32* %6
%16 = bitcast %struct.sockaddr_in* %7 to i8*
%17 = call i32 @bzero(i8* %16, i32 12)
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @inet_addr(i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %24, i32* %25
%26 = call i32 @htons(i32 4711)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %6
%29 = bitcast { i64, i32 }* %10 to i8*
%30 = bitcast %struct.sockaddr_in* %7 to i8*
%31 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %10, i32 0, i32 0
%32 = load i64, i64* %31
%33 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %10, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i32 @connect_to_socket(i32 %28, i64 %32, i32 %34)
br label %36
36: ; preds = %2, %47
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%39 = call i32 @bzero(i8* %38, i32 256)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %40, i32 256, i32 %41)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %36
br label %61
47: ; preds = %36
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = load i32, i32* %6
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%52 = call i32 @send_message(i32 %50, i8* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = call i32 @bzero(i8* %54, i32 256)
%56 = load i32, i32* %6
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%58 = call i32 @get_message(i32 %56, i8* %57)
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %36
61: ; preds = %46
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@.str = [20 x i8] c"Message to server: \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"quit\0A\00"
@.str.2 = [13 x i8] c"sending: %s\0A\00"
@.str.4 = [17 x i8] c"server sayz: %s\0A\00"
@str = [21 x i8] c"waiting for reply...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = call i32 @bzero(i8* %7, i32 256)
%10 = call i32 @bzero(i8* %8, i32 256)
%11 = tail call i32 (...) @create_socket()
%12 = call i32 @bzero(i8* %6, i32 12)
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @inet_addr(i8* %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 4711)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to i64*
%22 = load i64, i64* %21
%23 = tail call i32 @connect_to_socket(i32 %11, i64 %22, i32 %15)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @bzero(i8* %8, i32 256)
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %8, i32 256, i32 %26)
%28 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %43, label %30
30: ; preds = %2, %30
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%32 = call i32 @send_message(i32 %11, i8* %8)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%34 = call i32 @bzero(i8* %7, i32 256)
%35 = call i32 @get_message(i32 %11, i8* %7)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%38 = call i32 @bzero(i8* %8, i32 256)
%39 = load i32, i32* @stdin
%40 = call i32 @fgets(i8* %8, i32 256, i32 %39)
%41 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %30
43: ; preds = %30, %2
%44 = call i32 @close(i32 %11)
ret i32 0
}