#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int strlen(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int /*<<< orphan*/ verbose(int, char *, char *);
int write(int, char *, int);
int send_message(int sock, char *msg) {
  ssize_t len_send = 0;
  ssize_t len = 0;
  int size = strlen(msg);
  verbose(4, "msg: %s\n", msg);
  for (; len != size; len += len_send) {
    if ((len_send = write(sock, msg + len, strlen(msg) - len)) == -1) {
      syslog(LOG_ERR, "Failed to send message\n");
      return (-1);
    }
    if (len_send == 0)
      break;
  }
  return (0);
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x4,%edi
lea    0xe87(%rip),%rsi
call   1060 <verbose@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1208 <send_message+0xc8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
sub    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e6 <send_message+0xa6>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <send_message+0xcf>
cmpl   $0x0,-0x14(%rbp)
jne    11f5 <send_message+0xb5>
jmp    1208 <send_message+0xc8>
jmp    11fa <send_message+0xba>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    117e <send_message+0x3e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0xe9d(%rip),%rsi
mov    $0x4,%edi
mov    %r12,%rdx
call   1060 <verbose@plt>
test   %r15d,%r15d
je     11ae <send_message+0x6e>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rbp
lea    (%r12,%rbp,1),%r13
mov    %r12,%rdi
call   1040 <strlen@plt>
sub    %ebp,%eax
mov    %r14d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
je     11cc <send_message+0x8c>
cmp    $0xffffffff,%eax
je     11b2 <send_message+0x72>
add    %eax,%ebx
cmp    %r15d,%ebx
jne    1180 <send_message+0x40>
xor    %eax,%eax
jmp    11cc <send_message+0x8c>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <syslog@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"msg: %s\0A\00"
@LOG_ERR = global i32 0
@.str.1 = [24 x i8] c"Failed to send message\0A\00"
define i32 @send_message(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 @verbose(i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %37, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %8
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = load i32, i32* %4
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = load i32, i32* %7
%26 = sub nsw i32 %24, %25
%27 = call i32 @write(i32 %18, i8* %22, i32 %26)
store i32 %27, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = load i32, i32* @LOG_ERR
%31 = call i32 @syslog(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
32: ; preds = %17
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
br label %41
36: ; preds = %32
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = add nsw i32 %39, %38
store i32 %40, i32* %7
br label %13
41: ; preds = %35, %13
store i32 0, i32* %3
br label %42
42: ; preds = %41, %29
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [9 x i8] c"msg: %s\0A\00"
@LOG_ERR = global i32 0
@.str.1 = [24 x i8] c"Failed to send message\0A\00"
define i32 @send_message(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @verbose(i32 4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = icmp eq i32 %3, 0
br i1 %5, label %19, label %6
6: ; preds = %2, %16
%7 = phi i32 [ %17, %16 ], [ 0, %2 ]
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = tail call i32 @strlen(i8* %1)
%11 = sub nsw i32 %10, %7
%12 = tail call i32 @write(i32 %0, i8* %9, i32 %11)
switch i32 %12, label %16 [
i32 -1, label %13
i32 0, label %19
]
13: ; preds = %6
%14 = load i32, i32* @LOG_ERR
%15 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %19
16: ; preds = %6
%17 = add nsw i32 %12, %7
%18 = icmp eq i32 %17, %3
br i1 %18, label %19, label %6
19: ; preds = %6, %16, %2, %13
%20 = phi i32 [ -1, %13 ], [ 0, %2 ], [ %12, %6 ], [ 0, %16 ]
ret i32 %20
}