#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 */
struct iovec {
  char *iov_base;
  int iov_len;
};

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ h_errno;
scalar_t__ hstrerror(int /*<<< orphan*/);
void *strlen(char const *);
int /*<<< orphan*/ writev(int /*<<< orphan*/, struct iovec *, int);
void herror(const char *s) {
  struct iovec iov[4];
  register struct iovec *v = iov;
  if (s && *s) {
    v->iov_base = (char *)s;
    v->iov_len = strlen(s);
    v++;
    v->iov_base = ": ";
    v->iov_len = 2;
    v++;
  }
  v->iov_base = (char *)hstrerror(h_errno);
  v->iov_len = strlen(v->iov_base);
  v++;
  v->iov_base = "\n";
  v->iov_len = 1;
  writev(STDERR_FILENO, iov, (v - iov) + 1);
}


x86 assembly (clang, -O0):
<herror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ad <herror+0x7d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ad <herror+0x7d>
mov    -0x8(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x58(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
lea    0xe6d(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
movl   $0x2,0x8(%rax)
mov    -0x58(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x58(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <hstrerror@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x58(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
lea    0xe12(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rax
lea    -0x50(%rbp),%rcx
sub    %rcx,%rax
sar    $0x4,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <writev@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<herror>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsp,%r14
mov    %r14,%rbx
test   %rdi,%rdi
je     1170 <herror+0x40>
cmpb   $0x0,(%rdi)
mov    %r14,%rbx
je     1170 <herror+0x40>
mov    %rdi,(%rsp)
call   1040 <strlen@plt>
mov    %eax,0x8(%rsp)
lea    0xea2(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x2,0x18(%rsp)
lea    0x20(%rsp),%rbx
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1050 <hstrerror@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,0x8(%rbx)
lea    0x10(%rbx),%rdx
lea    0xe6c(%rip),%rax
mov    %rax,0x10(%rbx)
movl   $0x1,0x18(%rbx)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
sub    %r14,%rdx
shr    $0x4,%rdx
add    $0x1,%edx
mov    %r14,%rsi
call   1030 <writev@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [3 x i8] c": \00"
@h_errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@STDERR_FILENO = global i32 0
define void @herror(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x %struct.iovec]
%4 = alloca %struct.iovec*
store i8* %0, i8** %2
%5 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
store %struct.iovec* %5, %struct.iovec** %4
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %30
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load %struct.iovec*, %struct.iovec** %4
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 0
store i8* %14, i8** %16
%17 = load i8*, i8** %2
%18 = call i8* @strlen(i8* %17)
%19 = ptrtoint i8* %18 to i32
%20 = load %struct.iovec*, %struct.iovec** %4
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i32 0, i32 1
store i32 %19, i32* %21
%22 = load %struct.iovec*, %struct.iovec** %4
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 1
store %struct.iovec* %23, %struct.iovec** %4
%24 = load %struct.iovec*, %struct.iovec** %4
%25 = getelementptr inbounds %struct.iovec, %struct.iovec* %24, i32 0, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %25
%26 = load %struct.iovec*, %struct.iovec** %4
%27 = getelementptr inbounds %struct.iovec, %struct.iovec* %26, i32 0, i32 1
store i32 2, i32* %27
%28 = load %struct.iovec*, %struct.iovec** %4
%29 = getelementptr inbounds %struct.iovec, %struct.iovec* %28, i32 1
store %struct.iovec* %29, %struct.iovec** %4
br label %30
30: ; preds = %13, %8, %1
%31 = load i32, i32* @h_errno
%32 = call i64 @hstrerror(i32 %31)
%33 = inttoptr i64 %32 to i8*
%34 = load %struct.iovec*, %struct.iovec** %4
%35 = getelementptr inbounds %struct.iovec, %struct.iovec* %34, i32 0, i32 0
store i8* %33, i8** %35
%36 = load %struct.iovec*, %struct.iovec** %4
%37 = getelementptr inbounds %struct.iovec, %struct.iovec* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i8* @strlen(i8* %38)
%40 = ptrtoint i8* %39 to i32
%41 = load %struct.iovec*, %struct.iovec** %4
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %41, i32 0, i32 1
store i32 %40, i32* %42
%43 = load %struct.iovec*, %struct.iovec** %4
%44 = getelementptr inbounds %struct.iovec, %struct.iovec* %43, i32 1
store %struct.iovec* %44, %struct.iovec** %4
%45 = load %struct.iovec*, %struct.iovec** %4
%46 = getelementptr inbounds %struct.iovec, %struct.iovec* %45, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %46
%47 = load %struct.iovec*, %struct.iovec** %4
%48 = getelementptr inbounds %struct.iovec, %struct.iovec* %47, i32 0, i32 1
store i32 1, i32* %48
%49 = load i32, i32* @STDERR_FILENO
%50 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%51 = load %struct.iovec*, %struct.iovec** %4
%52 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%53 = ptrtoint %struct.iovec* %51 to i64
%54 = ptrtoint %struct.iovec* %52 to i64
%55 = sub i64 %53, %54
%56 = sdiv exact i64 %55, 16
%57 = add nsw i64 %56, 1
%58 = trunc i64 %57 to i32
%59 = call i32 @writev(i32 %49, %struct.iovec* %50, i32 %58)
ret void
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [3 x i8] c": \00"
@h_errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@STDERR_FILENO = global i32 0
define void @herror(i8* %0) {
%2 = alloca [4 x %struct.iovec]
%3 = bitcast [4 x %struct.iovec]* %2 to i8*
%4 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 0, i32 0
store i8* %0, i8** %10
%11 = tail call i8* @strlen(i8* %0)
%12 = ptrtoint i8* %11 to i64
%13 = trunc i64 %12 to i32
%14 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 1, i32 1
store i32 2, i32* %16
%17 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 2
br label %18
18: ; preds = %9, %6, %1
%19 = phi %struct.iovec* [ %17, %9 ], [ %4, %6 ], [ %4, %1 ]
%20 = load i32, i32* @h_errno
%21 = tail call i64 @hstrerror(i32 %20)
%22 = inttoptr i64 %21 to i8*
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i64 0, i32 0
store i8* %22, i8** %23
%24 = tail call i8* @strlen(i8* %22)
%25 = ptrtoint i8* %24 to i64
%26 = trunc i64 %25 to i32
%27 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i64 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i64 1
%29 = getelementptr inbounds %struct.iovec, %struct.iovec* %28, i64 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %29
%30 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i64 1, i32 1
store i32 1, i32* %30
%31 = load i32, i32* @STDERR_FILENO
%32 = ptrtoint %struct.iovec* %28 to i64
%33 = ptrtoint [4 x %struct.iovec]* %2 to i64
%34 = sub i64 %32, %33
%35 = lshr exact i64 %34, 4
%36 = trunc i64 %35 to i32
%37 = add i32 %36, 1
%38 = call i32 @writev(i32 %31, %struct.iovec* %4, i32 %37)
ret void
}