#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                  int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
void sendMessage(int s, char *buf, int buflen, struct sockaddr *from,
                 socklen_t fromlen) {
  printf("Usuario: ");
  fgets(buf, buflen, stdin);
  buf[strlen(buf) - 1] = '\0';
  if (sendto(s, buf, buflen, 0, from, fromlen) < 0) {
    perror("sendto()");
    exit(2);
  }
  printf("Mensagem: ");
  fgets(buf, buflen, stdin);
  buf[strlen(buf) - 1] = '\0';
  if (sendto(s, buf, buflen + 1, 0, from, fromlen) < 0) {
    perror("sendto()");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%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
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
xor    %ecx,%ecx
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    11f5 <sendMessage+0x95>
lea    0xe24(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%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
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
xor    %ecx,%ecx
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    1273 <sendMessage+0x113>
lea    0xda6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r12d
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e5c(%rip),%r13
mov    0x0(%r13),%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    %r12d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
js     1218 <sendMessage+0xb8>
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    0x0(%r13),%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    %r12d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r14d,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
js     1218 <sendMessage+0xb8>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdeb(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

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

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