#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*/ write(int /*<<< orphan*/, char *, int);
void herror(const char *s) {
  struct iovec iov[4];
  struct iovec *v = iov;
  if (s != NULL && *s != '\0') {
    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;
  do {
    int i;
    for (i = 0; i < ((v - iov) + 1); ++i) {
      write((STDERR_FILENO), (iov)[i].iov_base, (iov)[i].iov_len);
    }
  } while (0);
}


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)
movl   $0x0,-0x5c(%rbp)
movslq -0x5c(%rbp),%rax
mov    -0x58(%rbp),%rcx
lea    -0x50(%rbp),%rdx
sub    %rdx,%rcx
sar    $0x4,%rcx
add    $0x1,%rcx
cmp    %rcx,%rax
jge    1266 <herror+0x136>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
movslq -0x5c(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
movslq -0x5c(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%edx
call   1030 <write@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1206 <herror+0xd6>
jmp    126b <herror+0x13b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<herror>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsp,%r14
mov    %r14,%r15
test   %rdi,%rdi
je     1174 <herror+0x44>
cmpb   $0x0,(%rdi)
mov    %r14,%r15
je     1174 <herror+0x44>
mov    %rdi,(%rsp)
call   1040 <strlen@plt>
mov    %eax,0x8(%rsp)
lea    0xe9e(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x2,0x18(%rsp)
lea    0x20(%rsp),%r15
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1050 <hstrerror@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,0x8(%r15)
lea    0x10(%r15),%r12
lea    0xe67(%rip),%rax
mov    %rax,0x10(%r15)
movl   $0x1,0x18(%r15)
sub    %r14,%r12
js     11e8 <herror+0xb8>
shr    $0x4,%r12
add    $0x1,%r12
lea    0x8(%rsp),%rbx
mov    0x2e17(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    -0x8(%rbx),%rsi
mov    (%rbx),%edx
call   1030 <write@plt>
add    $0x10,%rbx
add    $0xffffffffffffffff,%r12
jne    11d0 <herror+0xa0>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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*
%5 = alloca i32
store i8* %0, i8** %2
%6 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
store %struct.iovec* %6, %struct.iovec** %4
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %31
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = load %struct.iovec*, %struct.iovec** %4
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 0
store i8* %15, i8** %17
%18 = load i8*, i8** %2
%19 = call i8* @strlen(i8* %18)
%20 = ptrtoint i8* %19 to i32
%21 = load %struct.iovec*, %struct.iovec** %4
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 1
store i32 %20, i32* %22
%23 = load %struct.iovec*, %struct.iovec** %4
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %23, i32 1
store %struct.iovec* %24, %struct.iovec** %4
%25 = load %struct.iovec*, %struct.iovec** %4
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %26
%27 = load %struct.iovec*, %struct.iovec** %4
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 1
store i32 2, i32* %28
%29 = load %struct.iovec*, %struct.iovec** %4
%30 = getelementptr inbounds %struct.iovec, %struct.iovec* %29, i32 1
store %struct.iovec* %30, %struct.iovec** %4
br label %31
31: ; preds = %14, %9, %1
%32 = load i32, i32* @h_errno
%33 = call i64 @hstrerror(i32 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load %struct.iovec*, %struct.iovec** %4
%36 = getelementptr inbounds %struct.iovec, %struct.iovec* %35, i32 0, i32 0
store i8* %34, i8** %36
%37 = load %struct.iovec*, %struct.iovec** %4
%38 = getelementptr inbounds %struct.iovec, %struct.iovec* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i8* @strlen(i8* %39)
%41 = ptrtoint i8* %40 to i32
%42 = load %struct.iovec*, %struct.iovec** %4
%43 = getelementptr inbounds %struct.iovec, %struct.iovec* %42, i32 0, i32 1
store i32 %41, i32* %43
%44 = load %struct.iovec*, %struct.iovec** %4
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %44, i32 1
store %struct.iovec* %45, %struct.iovec** %4
%46 = load %struct.iovec*, %struct.iovec** %4
%47 = getelementptr inbounds %struct.iovec, %struct.iovec* %46, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %47
%48 = load %struct.iovec*, %struct.iovec** %4
%49 = getelementptr inbounds %struct.iovec, %struct.iovec* %48, i32 0, i32 1
store i32 1, i32* %49
br label %50
50: ; preds = %31
store i32 0, i32* %5
br label %51
51: ; preds = %75, %50
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = load %struct.iovec*, %struct.iovec** %4
%55 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%56 = ptrtoint %struct.iovec* %54 to i64
%57 = ptrtoint %struct.iovec* %55 to i64
%58 = sub i64 %56, %57
%59 = sdiv exact i64 %58, 16
%60 = add nsw i64 %59, 1
%61 = icmp slt i64 %53, %60
br i1 %61, label %62, label %78
62: ; preds = %51
%63 = load i32, i32* @STDERR_FILENO
%64 = load i32, i32* %5
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 %65
%67 = getelementptr inbounds %struct.iovec, %struct.iovec* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 %70
%72 = getelementptr inbounds %struct.iovec, %struct.iovec* %71, i32 0, i32 1
%73 = load i32, i32* %72
%74 = call i32 @write(i32 %63, i8* %68, i32 %73)
br label %75
75: ; preds = %62
%76 = load i32, i32* %5
%77 = add nsw i32 %76, 1
store i32 %77, i32* %5
br label %51
78: ; preds = %51
br label %79
79: ; preds = %78
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 = ptrtoint %struct.iovec* %28 to i64
%32 = ptrtoint [4 x %struct.iovec]* %2 to i64
%33 = sub i64 %31, %32
%34 = icmp slt i64 %33, 0
br i1 %34, label %47, label %35
35: ; preds = %18
%36 = lshr i64 %33, 4
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %45, %37 ]
%39 = load i32, i32* @STDERR_FILENO
%40 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 %38, i32 0
%41 = load i8*, i8** %40
%42 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 %38, i32 1
%43 = load i32, i32* %42
%44 = call i32 @write(i32 %39, i8* %41, i32 %43)
%45 = add nuw nsw i64 %38, 1
%46 = icmp eq i64 %38, %36
br i1 %46, label %47, label %37
47: ; preds = %37, %18
ret void
}