#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ h_errno;
scalar_t__ hstrerror(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void *strlen(char const *);
void herror(const char *s) {
  struct iovec iov[4];
  register struct iovec *v = iov;
  int i;
  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;
  for (i = 0; i < (v - iov) + 1; i++)
    fprintf(stderr, iov[i].iov_base);
}


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   1030 <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   1030 <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    1254 <herror+0x124>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
movslq -0x5c(%rbp),%rcx
lea    -0x50(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1040 <fprintf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1206 <herror+0xd6>
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   1030 <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   1030 <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     11d5 <herror+0xa5>
shr    $0x4,%r12
add    $0x1,%r12
mov    %rsp,%rbx
mov    0x2e19(%rip),%r14
nop
mov    (%r14),%edi
mov    (%rbx),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rbx
add    $0xffffffffffffffff,%r12
jne    11c0 <herror+0x90>
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 = 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
store i32 0, i32* %5
br label %50
50: ; preds = %69, %31
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = load %struct.iovec*, %struct.iovec** %4
%54 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%55 = ptrtoint %struct.iovec* %53 to i64
%56 = ptrtoint %struct.iovec* %54 to i64
%57 = sub i64 %55, %56
%58 = sdiv exact i64 %57, 16
%59 = add nsw i64 %58, 1
%60 = icmp slt i64 %52, %59
br i1 %60, label %61, label %72
61: ; preds = %50
%62 = load i32, i32* @stderr
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 %64
%66 = getelementptr inbounds %struct.iovec, %struct.iovec* %65, i32 0, i32 0
%67 = load i8*, i8** %66
%68 = call i32 @fprintf(i32 %62, i8* %67)
br label %69
69: ; preds = %61
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
br label %50
72: ; preds = %50
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 = 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 %45, label %35
35: ; preds = %18
%36 = lshr i64 %33, 4
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %43, %37 ]
%39 = load i32, i32* @stderr
%40 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 %38, i32 0
%41 = load i8*, i8** %40
%42 = call i32 @fprintf(i32 %39, i8* %41)
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %38, %36
br i1 %44, label %45, label %37
45: ; preds = %37, %18
ret void
}