#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*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, scalar_t__);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int sendline(int sock, const char *str) {
  char *buf;
  buf = malloc(strlen(str) + 2);
  memset(buf, 0, strlen(str) + 2);
  strcpy(buf, str);
  *(buf + strlen(buf)) = '\n';
  if (send(sock, buf, strlen(buf), 0) != strlen(buf)) {
    free(buf);
    return 0;
  }
  free(buf);
  return 1;
}


x86 assembly (clang, -O0):
<sendline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x2,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
add    $0x2,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     122e <sendline+0xce>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    123e <sendline+0xde>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movb   $0xa,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
cmp    %rax,%r14
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sendline(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 2
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load i8*, i8** %5
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %13, 2
%15 = call i32 @memset(i8* %11, i32 0, i64 %14)
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 10, i8* %22
%23 = load i32, i32* %4
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i64 @strlen(i8* %25)
%27 = call i64 @send(i32 %23, i8* %24, i64 %26, i32 0)
%28 = load i8*, i8** %6
%29 = call i64 @strlen(i8* %28)
%30 = icmp ne i64 %27, %29
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
store i32 0, i32* %3
br label %37
34: ; preds = %2
%35 = load i8*, i8** %6
%36 = call i32 @free(i8* %35)
store i32 1, i32* %3
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @sendline(i32 %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = add nsw i64 %3, 2
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 @memset(i8* %5, i32 0, i64 %4)
%7 = tail call i32 @strcpy(i8* %5, i8* %1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 10, i8* %9
%10 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%11 = tail call i64 @send(i32 %0, i8* %5, i64 %10, i32 0)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%13 = icmp eq i64 %11, %12
%14 = tail call i32 @free(i8* %5)
%15 = zext i1 %13 to i32
ret i32 %15
}