#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*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char const *);
int write(int, char const *, int);
int sendFunc(int wfd, const char *msg) {
  int ret = 0, save_errno, send_len;
  char head_buff[32];
  if (0 >= wfd)
    return -1;
  if (NULL == msg || 0 == msg[0])
    return -2;
  printf("pipe_send : %s\n", msg);
  do {
    send_len = strlen(msg);
    snprintf(head_buff, 32, "vsec:");
    ret = write(wfd, head_buff, 8);
    printf("step[1] >> send_buff is \"%s\" and ret is %d\n", head_buff, ret);
    if (8 != ret) {
      ret = -3;
      break;
    }
    snprintf(head_buff, 32, "%010d", send_len + 1);
    ret = write(wfd, head_buff, 10);
    printf("step[2] >> send_buff is \"%s\" and ret is %d\n", head_buff, ret);
    if (10 != ret) {
      ret = -4;
      break;
    }
    ret = write(wfd, msg, strlen(msg) + 1);
    printf("step[3] >> send_buff is \"%s\" and ret is %d\n", msg, ret);
    if (send_len + 1 != ret) {
      ret = -5;
      break;
    }
  } while (0);
  printf("pipe_send : ret=%d\n", ret);
  return ret;
}


x86 assembly (clang, -O0):
<sendFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jl     116d <sendFunc+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e5 <sendFunc+0x1a5>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     118a <sendFunc+0x4a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1196 <sendFunc+0x56>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12e5 <sendFunc+0x1a5>
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
lea    0xe4c(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x8,%eax
cmp    -0x14(%rbp),%eax
je     120e <sendFunc+0xce>
movl   $0xfffffffd,-0x14(%rbp)
jmp    12ce <sendFunc+0x18e>
lea    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    $0x20,%esi
lea    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xa,%eax
cmp    -0x14(%rbp),%eax
je     126e <sendFunc+0x12e>
movl   $0xfffffffc,-0x14(%rbp)
jmp    12ce <sendFunc+0x18e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
je     12c9 <sendFunc+0x189>
movl   $0xfffffffb,-0x14(%rbp)
jmp    12ce <sendFunc+0x18e>
jmp    12ce <sendFunc+0x18e>
mov    -0x14(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendFunc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
test   %edi,%edi
jle    1272 <sendFunc+0x132>
mov    %rsi,%r12
mov    $0xfffffffe,%ebp
test   %rsi,%rsi
je     1277 <sendFunc+0x137>
cmpb   $0x0,(%r12)
je     1277 <sendFunc+0x137>
mov    %edi,%r15d
lea    0xe86(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe7a(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%ebx
lea    0xe55(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffd,%ebp
cmp    $0x8,%ebx
jne    1260 <sendFunc+0x120>
add    $0x1,%r14d
lea    0xe5c(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    %eax,%ebx
lea    0xe34(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffc,%ebp
cmp    $0xa,%ebx
jne    1260 <sendFunc+0x120>
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1030 <write@plt>
mov    %eax,%ebx
lea    0xe2b(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,%r14d
mov    $0xfffffffb,%ebp
cmove  %ebx,%ebp
lea    0xe39(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1277 <sendFunc+0x137>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"pipe_send : %s\0A\00"
@.str.1 = [6 x i8] c"vsec:\00"
@.str.2 = [44 x i8] c"step[1] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.3 = [6 x i8] c"%010d\00"
@.str.4 = [44 x i8] c"step[2] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.5 = [44 x i8] c"step[3] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.6 = [20 x i8] c"pipe_send : ret=%d\0A\00"
define i32 @sendFunc(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
%10 = load i32, i32* %4
%11 = icmp sge i32 0, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %74
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp eq i8* null, %14
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %23
22: ; preds = %16, %13
store i32 -2, i32* %3
br label %74
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %8
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %29, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %4
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 8)
store i32 %33, i32* %6
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %35)
%37 = load i32, i32* %6
%38 = icmp ne i32 8, %37
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 -3, i32* %6
br label %70
40: ; preds = %26
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
%44 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %41, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %4
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%47 = call i32 @write(i32 %45, i8* %46, i32 10)
store i32 %47, i32* %6
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %48, i32 %49)
%51 = load i32, i32* %6
%52 = icmp ne i32 10, %51
br i1 %52, label %53, label %54
53: ; preds = %40
store i32 -4, i32* %6
br label %70
54: ; preds = %40
%55 = load i32, i32* %4
%56 = load i8*, i8** %5
%57 = load i8*, i8** %5
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %58, 1
%60 = call i32 @write(i32 %55, i8* %56, i32 %59)
store i32 %60, i32* %6
%61 = load i8*, i8** %5
%62 = load i32, i32* %6
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %61, i32 %62)
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
%66 = load i32, i32* %6
%67 = icmp ne i32 %65, %66
br i1 %67, label %68, label %69
68: ; preds = %54
store i32 -5, i32* %6
br label %70
69: ; preds = %54
br label %70
70: ; preds = %69, %68, %53, %39
%71 = load i32, i32* %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %6
store i32 %73, i32* %3
br label %74
74: ; preds = %70, %22, %12
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [16 x i8] c"pipe_send : %s\0A\00"
@.str.1 = [6 x i8] c"vsec:\00"
@.str.2 = [44 x i8] c"step[1] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.3 = [6 x i8] c"%010d\00"
@.str.4 = [44 x i8] c"step[2] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.5 = [44 x i8] c"step[3] >> send_buff is \22%s\22 and ret is %d\0A\00"
@.str.6 = [20 x i8] c"pipe_send : ret=%d\0A\00"
define i32 @sendFunc(i32 %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 1
br i1 %5, label %34, label %6
6: ; preds = %2
%7 = icmp eq i8* %1, null
br i1 %7, label %34, label %8
8: ; preds = %6
%9 = load i8, i8* %1
%10 = icmp eq i8 %9, 0
br i1 %10, label %34, label %11
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%13 = tail call i32 @strlen(i8* %1)
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @write(i32 %0, i8* %4, i32 8)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %15)
%17 = icmp eq i32 %15, 8
br i1 %17, label %18, label %31
18: ; preds = %11
%19 = add nsw i32 %13, 1
%20 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 @write(i32 %0, i8* %4, i32 10)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 %21)
%23 = icmp eq i32 %21, 10
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = call i32 @strlen(i8* %1)
%26 = add nsw i32 %25, 1
%27 = call i32 @write(i32 %0, i8* %1, i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %1, i32 %27)
%29 = icmp eq i32 %19, %27
%30 = select i1 %29, i32 %27, i32 -5
br label %31
31: ; preds = %18, %11, %24
%32 = phi i32 [ %30, %24 ], [ -3, %11 ], [ -4, %18 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %6, %8, %2, %31
%35 = phi i32 [ %32, %31 ], [ -1, %2 ], [ -2, %8 ], [ -2, %6 ]
ret i32 %35
}