#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int sendMessage(int sock, char *msg) {
  int sent = send(sock, msg, strlen(msg), 0);
  if (sent == -1) {
    perror("sent");
    return -1;
  } else if (sent < strlen(msg)) {
    fprintf(stderr,
            "Error sending message: Expected to send %d bytes but only sent %d "
            "bytes",
            (int)strlen(msg), sent);
    return -1;
  }
  return sent;
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    119b <sendMessage+0x5b>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <sendMessage+0xb7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    11ec <sendMessage+0xac>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <sendMessage+0xb7>
jmp    11f1 <sendMessage+0xb1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     11a1 <sendMessage+0x61>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
jge    119a <sendMessage+0x5a>
mov    0x2e67(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe7b(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
mov    %ebx,%ecx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe58(%rip),%rdi
call   1060 <perror@plt>
jmp    1195 <sendMessage+0x55>

LLVM IR (-O0):
@.str = [5 x i8] c"sent\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"Error sending message: Expected to send %d bytes but only sent %d bytes\00"
define i32 @sendMessage(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = load i8*, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @send(i32 %7, i8* %8, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = load i32, i32* %6
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
store i32 -1, i32* %3
br label %30
27: ; preds = %16
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %21, %14
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"sent\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"Error sending message: Expected to send %d bytes but only sent %d bytes\00"
define i32 @sendMessage(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @send(i32 %0, i8* %1, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %1)
%10 = icmp slt i32 %4, %9
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @strlen(i8* %1)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %4)
br label %15
15: ; preds = %8, %11, %6
%16 = phi i32 [ -1, %6 ], [ -1, %11 ], [ %4, %8 ]
ret i32 %16
}