#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int _write_bytes(int, char *, size_t);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
size_t _send_msg(int fd, char *buf, size_t size) {
  char header[10];
  size_t data_sent;
  (void)sprintf(header, "%08lu\n", (uint32_t)size);
  if (_write_bytes(fd, header, 9) != 9) {
    perror("writing message header");
    exit(1);
  }
  data_sent = _write_bytes(fd, buf, size);
  if (data_sent != size) {
    perror("writing message");
    exit(1);
  }
  return data_sent;
}


x86 assembly (clang, -O0):
<_send_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xe9c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x9,%edx
call   1030 <_write_bytes@plt>
cmp    $0x9,%eax
je     1199 <_send_msg+0x59>
lea    0xe7d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <_write_bytes@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11d3 <_send_msg+0x93>
lea    0xe5a(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_send_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xea7(%rip),%rsi
lea    0xe(%rsp),%r15
mov    %r15,%rdi
call   1050 <sprintf@plt>
mov    $0x9,%edx
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <_write_bytes@plt>
cmp    $0x9,%eax
jne    119c <_send_msg+0x5c>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <_write_bytes@plt>
cltq
cmp    %rbx,%rax
jne    11a5 <_send_msg+0x65>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe64(%rip),%rdi
jmp    11ac <_send_msg+0x6c>
lea    0xe72(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%08lu\0A\00"
@.str.1 = [23 x i8] c"writing message header\00"
@.str.2 = [16 x i8] c"writing message\00"
define i64 @_send_msg(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [10 x i8]
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%10 = load i64, i64* %6
%11 = trunc i64 %10 to i32
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %4
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%15 = call i32 @_write_bytes(i32 %13, i8* %14, i64 9)
%16 = icmp ne i32 %15, 9
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = load i32, i32* %4
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i32 @_write_bytes(i32 %21, i8* %22, i64 %23)
%25 = sext i32 %24 to i64
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = load i64, i64* %6
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = load i64, i64* %8
ret i64 %33
}

LLVM IR (-O2):
@.str = [7 x i8] c"%08lu\0A\00"
@.str.1 = [23 x i8] c"writing message header\00"
@.str.2 = [16 x i8] c"writing message\00"
define i64 @_send_msg(i32 %0, i8* %1, i64 %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = trunc i64 %2 to i32
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @_write_bytes(i32 %0, i8* %5, i64 9)
%9 = icmp eq i32 %8, 9
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = call i32 @_write_bytes(i32 %0, i8* %1, i64 %2)
%15 = sext i32 %14 to i64
%16 = icmp eq i64 %15, %2
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
ret i64 %2
}