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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int writen(int, char *, int);
int sendMsg(int fd, void *vptr, int n) {
  char head[10 + 1];
  char *ptr = vptr;
  memset(head, 0x00, sizeof(head));
  snprintf(head, sizeof(head), "%010d", n);
  if ((writen(fd, head, sizeof(head))) != sizeof(head))
    return -1;
  if ((writen(fd, ptr, n)) != n)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<sendMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1f(%rbp),%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
lea    -0x1f(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xb,%esi
lea    0xe93(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x1f(%rbp),%rsi
mov    $0xb,%edx
call   1050 <writen@plt>
cltq
cmp    $0xb,%rax
je     119b <sendMsg+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <sendMsg+0x96>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <writen@plt>
cmp    -0x14(%rbp),%eax
je     11bf <sendMsg+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c6 <sendMsg+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMsg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xd(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xb,%edx
call   1040 <memset@plt>
lea    0xea3(%rip),%rdx
mov    %rbp,%rdi
mov    $0xb,%esi
mov    %ebx,%ecx
call   1030 <snprintf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
call   1050 <writen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xb,%ecx
jne    11a0 <sendMsg+0x70>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <writen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setne  %al
neg    %eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%010d\00"
define i32 @sendMsg(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [11 x i8]
%9 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
store i8* %10, i8** %9
%11 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 11)
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* %7
%15 = call i32 @snprintf(i8* %13, i32 11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
%17 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%18 = call i32 @writen(i32 %16, i8* %17, i32 11)
%19 = sext i32 %18 to i64
%20 = icmp ne i64 %19, 11
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %4
br label %31
22: ; preds = %3
%23 = load i32, i32* %5
%24 = load i8*, i8** %9
%25 = load i32, i32* %7
%26 = call i32 @writen(i32 %23, i8* %24, i32 %25)
%27 = load i32, i32* %7
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 -1, i32* %4
br label %31
30: ; preds = %22
store i32 0, i32* %4
br label %31
31: ; preds = %30, %29, %21
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"%010d\00"
define i32 @sendMsg(i32 %0, i8* %1, i32 %2) {
%4 = alloca [11 x i8]
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 11)
%7 = call i32 @snprintf(i8* %5, i32 11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
%8 = call i32 @writen(i32 %0, i8* %5, i32 11)
%9 = icmp eq i32 %8, 11
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = call i32 @writen(i32 %0, i8* %1, i32 %2)
%12 = icmp ne i32 %11, %2
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %3
%15 = phi i32 [ -1, %3 ], [ %13, %10 ]
ret i32 %15
}