#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*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int sendMessage(char buffer[], int sockfd) {
  printf("Please enter the message: ");
  bzero(buffer, 256);
  fgets(buffer, 255, stdin);
  char *pos;
  if ((pos = strchr(buffer, '\n')) != NULL)
    *pos = '\0';
  else
    error("ERROR removing the newline char from input");
  int n = write(sockfd, buffer, strlen(buffer));
  printf("\nHere is the message: %s\n", buffer);
  return n;
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1070 <fgets@plt>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11da <sendMessage+0x6a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e6 <sendMessage+0x76>
lea    0xe3a(%rip),%rdi
call   1080 <error@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1090 <bzero@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c0 <sendMessage+0x50>
movb   $0x0,(%rax)
jmp    11cc <sendMessage+0x5c>
lea    0xe54(%rip),%rdi
call   1080 <error@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebp
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"ERROR removing the newline char from input\00"
@.str.2 = [26 x i8] c"\0AHere is the message: %s\0A\00"
define i32 @sendMessage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %3
%9 = call i32 @bzero(i8* %8, i32 256)
%10 = load i8*, i8** %3
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 255, i32 %11)
%13 = load i8*, i8** %3
%14 = call i8* @strchr(i8* %13, i8 signext 10)
store i8* %14, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i8*, i8** %5
store i8 0, i8* %17
br label %20
18: ; preds = %2
%19 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %4
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
store i32 %25, i32* %6
%26 = load i8*, i8** %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
@.str = [27 x i8] c"Please enter the message: \00"
@stdin = global i32 0
@.str.1 = [43 x i8] c"ERROR removing the newline char from input\00"
@.str.2 = [26 x i8] c"\0AHere is the message: %s\0A\00"
define i32 @sendMessage(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @bzero(i8* %0, i32 256)
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* %0, i32 255, i32 %5)
%7 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8 0, i8* %7
br label %12
10: ; preds = %2
%11 = tail call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %9
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @write(i32 %1, i8* %0, i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0)
ret i32 %14
}