#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
void send_message(int client_socket) {
  char send_buf[1024];
  memset(send_buf, 0, 1024);
  int bytes;
  fgets(send_buf, 1024 - 1, stdin);
  fflush(0);
  bytes = send(client_socket, send_buf, 1024, 0);
  if (bytes < 0) {
    perror("send() failed");
  }
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11c7 <send_message+0x77>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1050 <fgets@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     11a9 <send_message+0x59>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
jmp    119f <send_message+0x4f>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [14 x i8] c"send() failed\00"
define void @send_message(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 1024)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 1023, i32 %8)
%10 = call i32 @fflush(i32 0)
%11 = load i32, i32* %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @send(i32 %11, i8* %12, i32 1024, i32 0)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %1
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [14 x i8] c"send() failed\00"
define void @send_message(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 1024)
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %3, i32 1023, i32 %5)
%7 = call i32 @fflush(i32 0)
%8 = call i32 @send(i32 %0, i8* %3, i32 1024, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
ret void
}