#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 */
scalar_t__ send_fd(int, int);
int strlen(char *);
int writen(int, char *, int);
int send_err(int clifd, int errcode, char *errmsg) {
  int n;
  if ((n = strlen(errmsg)) > 0) {
    if (writen(clifd, errmsg, n) != n) {
      return (-1);
    }
  }
  if (errcode >= 0) {
    errcode = -1;
  }
  if (send_fd(clifd, errcode) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<send_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1180 <send_err+0x50>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <writen@plt>
cmp    -0x1c(%rbp),%eax
je     117b <send_err+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <send_err+0x89>
jmp    1180 <send_err+0x50>
cmpl   $0x0,-0xc(%rbp)
jl     1191 <send_err+0x61>
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <send_fd@plt>
cmp    $0x0,%rax
jge    11b2 <send_err+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <send_err+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_err>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    %rdx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1166 <send_err+0x36>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <writen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ebp,%ecx
jne    117e <send_err+0x4e>
test   %r15d,%r15d
mov    $0xffffffff,%esi
cmovs  %r15d,%esi
mov    %r14d,%edi
call   1040 <send_fd@plt>
sar    $0x3f,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_err(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i32, i32* %5
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @writen(i32 %13, i8* %14, i32 %15)
%17 = load i32, i32* %8
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %4
br label %32
20: ; preds = %12
br label %21
21: ; preds = %20, %3
%22 = load i32, i32* %6
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 -1, i32* %6
br label %25
25: ; preds = %24, %21
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i64 @send_fd(i32 %26, i32 %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 -1, i32* %4
br label %32
31: ; preds = %25
store i32 0, i32* %4
br label %32
32: ; preds = %31, %30, %19
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @send_err(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @writen(i32 %0, i8* %2, i32 %4)
%8 = icmp eq i32 %7, %4
br i1 %8, label %9, label %15
9: ; preds = %6, %3
%10 = icmp slt i32 %1, -1
%11 = select i1 %10, i32 %1, i32 -1
%12 = tail call i64 @send_fd(i32 %0, i32 %11)
%13 = ashr i64 %12, 63
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %9, %6
%16 = phi i32 [ -1, %6 ], [ %14, %9 ]
ret i32 %16
}