#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 */

/* Variables and functions */
int EXIT_FAILURE;
int errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int ClientGreet(int sock) {
  char sendBuff[4096], rcvBuff[4096] = {0};
  int err = 0;
  printf("Message for server:\t");
  fgets(sendBuff, 4096, stdin);
  if (write(sock, sendBuff, strlen(sendBuff)) != strlen(sendBuff)) {
    err = errno;
    printf("Write error: errno: %i\n", err);
    return EXIT_FAILURE;
  }
  if (read(sock, rcvBuff, 4096) < 0) {
    err = errno;
    printf("Read error. errno: %i\n", err);
    return EXIT_FAILURE;
  }
  printf("Recieved: \t%s\n", rcvBuff);
  return 0;
}


x86 assembly (clang, -O0):
<ClientGreet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x2014(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1010(%rbp),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1080 <fgets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x202c(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x2028(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x202c(%rbp),%edi
mov    -0x2028(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x2020(%rbp)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x2020(%rbp),%rax
cmp    %rcx,%rax
je     1245 <ClientGreet+0xe5>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2014(%rbp)
mov    -0x2014(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <ClientGreet+0x153>
mov    -0x8(%rbp),%edi
lea    -0x2010(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    1297 <ClientGreet+0x137>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2014(%rbp)
mov    -0x2014(%rbp),%esi
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12b3 <ClientGreet+0x153>
lea    -0x2010(%rbp),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ClientGreet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
lea    0x1000(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jne    11f9 <ClientGreet+0x99>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
js     120b <ClientGreet+0xab>
lea    0xe59(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    122b <ClientGreet+0xcb>
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
jmp    121b <ClientGreet+0xbb>
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Message for server:\09\00"
@stdin = global i32 0
@errno = global i32 0
@.str.1 = [24 x i8] c"Write error: errno: %i\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [23 x i8] c"Read error. errno: %i\0A\00"
@.str.3 = [15 x i8] c"Recieved: \09%s\0A\00"
define i32 @ClientGreet(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca [4096 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast [4096 x i8]* %5 to i8*
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 4096, i32 %10)
%12 = load i32, i32* %3
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = call i64 @write(i32 %12, i8* %13, i64 %15)
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = icmp ne i64 %16, %18
br i1 %19, label %20, label %25
20: ; preds = %1
%21 = load i32, i32* @errno
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %2
br label %38
25: ; preds = %1
%26 = load i32, i32* %3
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%28 = call i64 @read(i32 %26, i8* %27, i32 4096)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @errno
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %2
br label %38
35: ; preds = %25
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 0, i32* %2
br label %38
38: ; preds = %35, %30, %20
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [21 x i8] c"Message for server:\09\00"
@stdin = global i32 0
@errno = global i32 0
@.str.1 = [24 x i8] c"Write error: errno: %i\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [23 x i8] c"Read error. errno: %i\0A\00"
@.str.3 = [15 x i8] c"Recieved: \09%s\0A\00"
define i32 @ClientGreet(i32 %0) {
%2 = alloca [4096 x i8]
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %4, i32 4096, i32 %7)
%9 = call i64 @strlen(i8* %4)
%10 = call i64 @write(i32 %0, i8* %4, i64 %9)
%11 = call i64 @strlen(i8* %4)
%12 = icmp eq i64 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @EXIT_FAILURE
br label %26
17: ; preds = %1
%18 = call i64 @read(i32 %0, i8* %5, i32 4096)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @errno
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @EXIT_FAILURE
br label %26
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %26
26: ; preds = %24, %20, %13
%27 = phi i32 [ %16, %13 ], [ %23, %20 ], [ 0, %24 ]
ret i32 %27
}