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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  int sockfd = 0;
  int n = 0;
  char recvBuff[1024];
  char sendBuff[1024];
  struct sockaddr_in serv_addr;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("\n Error : Could not create socket \n");
    return 1;
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(5000);
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    printf("\n Error : Connect Failed \n");
    return 1;
  }
  n = read(sockfd, recvBuff, 255);
  if (n < 0) {
    printf("Error\n");
  }
  printf("%s\n", recvBuff);
  printf("Kommet hit \n");
  while (1) {
    printf("Enter your message: ");
    fgets(sendBuff, 1024, stdin);
    strtok(sendBuff, "\n");
    write(sockfd, sendBuff, strlen(sendBuff));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11ff <main+0x5f>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x191>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x818(%rbp)
mov    $0x1388,%edi
call   1050 <htons@plt>
mov    %eax,-0x81c(%rbp)
lea    0xdff(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x820(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1268 <main+0xc8>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1331 <main+0x191>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1297 <main+0xf7>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x810(%rbp),%rdi
mov    0x2d0a(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x810(%rbp),%rdi
lea    0xd57(%rip),%rsi
call   10a0 <strtok@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x82c(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x82c(%rbp),%edi
mov    -0x828(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    12ba <main+0x11a>
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12bd <main+0x10d>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe02(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12c6 <main+0x116>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
jns    1241 <main+0x91>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
lea    0xdac(%rip),%r15
mov    0x2d7b(%rip),%r12
lea    0x410(%rsp),%rbp
lea    0xdab(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%edx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strtok@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1280 <main+0xd0>
lea    0xd89(%rip),%rdi
jmp    12cd <main+0x11d>
lea    0xd66(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [36 x i8] c"\0A Error : Could not create socket \0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [27 x i8] c"\0A Error : Connect Failed \0A\00"
@.str.3 = [7 x i8] c"Error\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [13 x i8] c"Kommet hit \0A\00"
@.str.6 = [21 x i8] c"Enter your message: \00"
@stdin = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %51
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 5000)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%23 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %51
27: ; preds = %13
%28 = load i32, i32* %2
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 255)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %27
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %35, %39
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 1024, i32 %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%45 = call i32 @strtok(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* %2
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @write(i32 %46, i8* %47, i32 %49)
br label %39
51: ; preds = %25, %11
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.6 = [21 x i8] c"Enter your message: \00"
@stdin = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
@str = [12 x i8] c"Kommet hit \00"
@str.8 = [6 x i8] c"Error\00"
@str.9 = [26 x i8] c"\0A Error : Connect Failed \00"
@str.10 = [35 x i8] c"\0A Error : Could not create socket \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.10, i64 0, i64 0))
br label %40
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 5000)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @connect(i32 %9, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.9, i64 0, i64 0))
br label %40
25: ; preds = %13
%26 = call i32 @read(i32 %9, i8* %4, i32 255)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = call i32 @puts(i8* %4)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %33, %30
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %5, i32 1024, i32 %35)
%37 = call i32 @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%38 = call i32 @strlen(i8* %5)
%39 = call i32 @write(i32 %9, i8* %5, i32 %38)
br label %33
40: ; preds = %23, %11
ret i32 1
}