#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
void sendMessage(int s, char *buf, int buflen) {
  printf("Usuario: ");
  fgets(buf, buflen, stdin);
  buf[strlen(buf) - 1] = '\0';
  if (send(s, buf, buflen, 0) < 0) {
    perror("send()");
    exit(2);
  }
  printf("Mensagem: ");
  fgets(buf, buflen, stdin);
  buf[strlen(buf) - 1] = '\0';
  if (send(s, buf, buflen + 1, 0) < 0) {
    perror("send()");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    11e5 <sendMessage+0x85>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    125b <sendMessage+0xfb>
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e66(%rip),%r15
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     11fc <sendMessage+0x9c>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
add    $0x1,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     11fc <sendMessage+0x9c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe07(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"Usuario: \00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"send()\00"
@.str.2 = [11 x i8] c"Mensagem: \00"
define void @sendMessage(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %8, i32 %9, i32 %10)
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
%18 = load i32, i32* %4
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = call i64 @send(i32 %18, i8* %19, i32 %20, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %3
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %28, i32 %29, i32 %30)
%32 = load i8*, i8** %5
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* %4
%39 = load i8*, i8** %5
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
%42 = call i64 @send(i32 %38, i8* %39, i32 %41, i32 0)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %26
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @exit(i32 2)
unreachable
47: ; preds = %26
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Usuario: \00"
@stdin = global i32 0
@.str.1 = [7 x i8] c"send()\00"
@.str.2 = [11 x i8] c"Mensagem: \00"
define void @sendMessage(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* %1, i32 %2, i32 %5)
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 0, i8* %10
%11 = tail call i64 @send(i32 %0, i8* %1, i32 %2, i32 0)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %3
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = tail call i32 @fgets(i8* %1, i32 %2, i32 %18)
%20 = tail call i32 @strlen(i8* %1)
%21 = add nsw i32 %20, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
%24 = add nsw i32 %2, 1
%25 = tail call i64 @send(i32 %0, i8* %1, i32 %24, i32 0)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @exit(i32 2)
unreachable
30: ; preds = %16
ret void
}