#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int send_buf(int fd, char *str) {
  int len = strlen(str);
  char buf[len + 2];
  sprintf(buf, "%s\r\n", str);
  if (send(fd, buf, len + 2, 0) < 0) {
    perror("send");
    return -1;
  }
  printf(">>> %s.\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<send_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe61(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
add    $0x2,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    11e1 <send_buf+0x91>
lea    0xe3c(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11ff <send_buf+0xaf>
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_buf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x2(%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1070 <sprintf@plt>
xor    %r14d,%r14d
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
js     11cc <send_buf+0x7c>
lea    0xe58(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe32(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11ba <send_buf+0x6a>

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0D\0A\00"
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [9 x i8] c">>> %s.\0A\00"
define i32 @send_buf(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 2
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
%17 = load i8*, i8** %5
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %4
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 2
%22 = call i64 @send(i32 %19, i8* %16, i32 %21, i32 0)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %9
br label %29
26: ; preds = %2
%27 = load i8*, i8** %5
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 0, i32* %3
store i32 1, i32* %9
br label %29
29: ; preds = %26, %24
%30 = load i8*, i8** %7
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0D\0A\00"
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [9 x i8] c">>> %s.\0A\00"
define i32 @send_buf(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 2
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = call i64 @send(i32 %0, i8* %6, i32 %4, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %10 ], [ 0, %12 ]
ret i32 %15
}