#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*/);
char *strchr(void const *, char const);
void *strlen(char *);
int /*<<< orphan*/ writev(int /*<<< orphan*/, struct iovec *, int);
void herror(const char *s) {
  struct iovec iov[4], *v = iov;
  char *t;
  if (s != NULL && *s != '\0') {
    t = ((s) ? strchr((const void *)(s), *(const char *)(const void *)(s))
             : NULL);
    v->iov_base = t;
    v->iov_len = strlen(t);
    v++;
    t = ((": ")
             ? strchr((const void *)(": "), *(const char *)(const void *)(": "))
             : NULL);
    v->iov_base = t;
    v->iov_len = 2;
    v++;
  }
  t = ((hstrerror(h_errno))
           ? strchr((const void *)(hstrerror(h_errno)),
                    *(const char *)(const void *)(hstrerror(h_errno)))
           : NULL);
  v->iov_base = t;
  v->iov_len = strlen(v->iov_base);
  v++;
  t = (("\n")
           ? strchr((const void *)("\n"), *(const char *)(const void *)("\n"))
           : NULL);
  v->iov_base = t;
  v->iov_len = 1;
  writev(STDERR_FILENO, iov, (v - iov) + 1);
}


x86 assembly (clang, -O0):
<herror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1232 <herror+0xf2>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1232 <herror+0xf2>
cmpq   $0x0,-0x8(%rbp)
je     1196 <herror+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x68(%rbp)
jmp    11a1 <herror+0x61>
xor    %eax,%eax
mov    %rax,-0x68(%rbp)
jmp    11a1 <herror+0x61>
mov    -0x68(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x60(%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    $0x1,%al
test   $0x1,%al
jne    11e1 <herror+0xa1>
jmp    11fd <herror+0xbd>
lea    0xe18(%rip),%rdi
movsbl 0xe11(%rip),%esi
call   1050 <strchr@plt>
mov    %rax,-0x70(%rbp)
jmp    1208 <herror+0xc8>
xor    %eax,%eax
mov    %rax,-0x70(%rbp)
jmp    1208 <herror+0xc8>
mov    -0x70(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
movl   $0x2,0x8(%rax)
mov    -0x58(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x58(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1060 <hstrerror@plt>
cmp    $0x0,%rax
je     127f <herror+0x13f>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   1060 <hstrerror@plt>
mov    %rax,-0x80(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1060 <hstrerror@plt>
mov    -0x80(%rbp),%rdi
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x78(%rbp)
jmp    128a <herror+0x14a>
xor    %eax,%eax
mov    %rax,-0x78(%rbp)
jmp    128a <herror+0x14a>
mov    -0x78(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%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    $0x1,%al
test   $0x1,%al
jne    12cd <herror+0x18d>
jmp    12ec <herror+0x1ac>
lea    0xd2f(%rip),%rdi
movsbl 0xd28(%rip),%esi
call   1050 <strchr@plt>
mov    %rax,-0x88(%rbp)
jmp    12fa <herror+0x1ba>
xor    %eax,%eax
mov    %rax,-0x88(%rbp)
jmp    12fa <herror+0x1ba>
mov    -0x88(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    0x2cb6(%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    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<herror>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsp,%rbx
test   %rdi,%rdi
je     1188 <herror+0x48>
mov    (%rdi),%al
test   %al,%al
je     1188 <herror+0x48>
movsbl %al,%esi
call   1050 <strchr@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,0x8(%rsp)
lea    0xe8a(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x2,0x18(%rsp)
lea    0x20(%rsp),%rbx
mov    0x2e59(%rip),%r15
mov    (%r15),%edi
call   1060 <hstrerror@plt>
test   %rax,%rax
je     11bf <herror+0x7f>
mov    (%r15),%edi
call   1060 <hstrerror@plt>
mov    %rax,%r14
mov    (%r15),%edi
call   1060 <hstrerror@plt>
movsbl (%rax),%esi
mov    %r14,%rdi
call   1050 <strchr@plt>
mov    %rax,%rdi
jmp    11c1 <herror+0x81>
xor    %edi,%edi
mov    %rdi,(%rbx)
call   1040 <strlen@plt>
mov    %eax,0x8(%rbx)
lea    0x10(%rbx),%rdx
lea    0xe2c(%rip),%rax
mov    %rax,0x10(%rbx)
movl   $0x1,0x18(%rbx)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
sub    %rsi,%rdx
shr    $0x4,%rdx
add    $0x1,%edx
call   1030 <writev@plt>
add    $0x40,%rsp
pop    %rbx
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 i8*
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 %48
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 %48
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = call i8* @strchr(i8* %18, i8 signext %20)
br label %23
22: ; preds = %14
br label %23
23: ; preds = %22, %17
%24 = phi i8* [ %21, %17 ], [ null, %22 ]
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = load %struct.iovec*, %struct.iovec** %4
%27 = getelementptr inbounds %struct.iovec, %struct.iovec* %26, i32 0, i32 0
store i8* %25, i8** %27
%28 = load i8*, i8** %5
%29 = call i8* @strlen(i8* %28)
%30 = ptrtoint i8* %29 to i32
%31 = load %struct.iovec*, %struct.iovec** %4
%32 = getelementptr inbounds %struct.iovec, %struct.iovec* %31, i32 0, i32 1
store i32 %30, i32* %32
%33 = load %struct.iovec*, %struct.iovec** %4
%34 = getelementptr inbounds %struct.iovec, %struct.iovec* %33, i32 1
store %struct.iovec* %34, %struct.iovec** %4
br i1 true, label %35, label %38
35: ; preds = %23
%36 = load i8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%37 = call i8* @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %36)
br label %39
38: ; preds = %23
br label %39
39: ; preds = %38, %35
%40 = phi i8* [ %37, %35 ], [ null, %38 ]
store i8* %40, i8** %5
%41 = load i8*, i8** %5
%42 = load %struct.iovec*, %struct.iovec** %4
%43 = getelementptr inbounds %struct.iovec, %struct.iovec* %42, i32 0, i32 0
store i8* %41, i8** %43
%44 = load %struct.iovec*, %struct.iovec** %4
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %44, i32 0, i32 1
store i32 2, i32* %45
%46 = load %struct.iovec*, %struct.iovec** %4
%47 = getelementptr inbounds %struct.iovec, %struct.iovec* %46, i32 1
store %struct.iovec* %47, %struct.iovec** %4
br label %48
48: ; preds = %39, %9, %1
%49 = load i32, i32* @h_errno
%50 = call i64 @hstrerror(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %61
52: ; preds = %48
%53 = load i32, i32* @h_errno
%54 = call i64 @hstrerror(i32 %53)
%55 = inttoptr i64 %54 to i8*
%56 = load i32, i32* @h_errno
%57 = call i64 @hstrerror(i32 %56)
%58 = inttoptr i64 %57 to i8*
%59 = load i8, i8* %58
%60 = call i8* @strchr(i8* %55, i8 signext %59)
br label %62
61: ; preds = %48
br label %62
62: ; preds = %61, %52
%63 = phi i8* [ %60, %52 ], [ null, %61 ]
store i8* %63, i8** %5
%64 = load i8*, i8** %5
%65 = load %struct.iovec*, %struct.iovec** %4
%66 = getelementptr inbounds %struct.iovec, %struct.iovec* %65, i32 0, i32 0
store i8* %64, i8** %66
%67 = load %struct.iovec*, %struct.iovec** %4
%68 = getelementptr inbounds %struct.iovec, %struct.iovec* %67, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = call i8* @strlen(i8* %69)
%71 = ptrtoint i8* %70 to i32
%72 = load %struct.iovec*, %struct.iovec** %4
%73 = getelementptr inbounds %struct.iovec, %struct.iovec* %72, i32 0, i32 1
store i32 %71, i32* %73
%74 = load %struct.iovec*, %struct.iovec** %4
%75 = getelementptr inbounds %struct.iovec, %struct.iovec* %74, i32 1
store %struct.iovec* %75, %struct.iovec** %4
br i1 true, label %76, label %79
76: ; preds = %62
%77 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%78 = call i8* @strchr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8 signext %77)
br label %80
79: ; preds = %62
br label %80
80: ; preds = %79, %76
%81 = phi i8* [ %78, %76 ], [ null, %79 ]
store i8* %81, i8** %5
%82 = load i8*, i8** %5
%83 = load %struct.iovec*, %struct.iovec** %4
%84 = getelementptr inbounds %struct.iovec, %struct.iovec* %83, i32 0, i32 0
store i8* %82, i8** %84
%85 = load %struct.iovec*, %struct.iovec** %4
%86 = getelementptr inbounds %struct.iovec, %struct.iovec* %85, i32 0, i32 1
store i32 1, i32* %86
%87 = load i32, i32* @STDERR_FILENO
%88 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%89 = load %struct.iovec*, %struct.iovec** %4
%90 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %3, i64 0, i64 0
%91 = ptrtoint %struct.iovec* %89 to i64
%92 = ptrtoint %struct.iovec* %90 to i64
%93 = sub i64 %91, %92
%94 = sdiv exact i64 %93, 16
%95 = add nsw i64 %94, 1
%96 = trunc i64 %95 to i32
%97 = call i32 @writev(i32 %87, %struct.iovec* %88, i32 %96)
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 %19, label %6
6: ; preds = %1
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = tail call i8* @strchr(i8* %0, i8 signext %7)
%11 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 0, i32 0
store i8* %10, i8** %11
%12 = tail call i8* @strlen(i8* %10)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 0, i32 1
store i32 %14, i32* %15
%16 = 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** %16
%17 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 1, i32 1
store i32 2, i32* %17
%18 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %2, i64 0, i64 2
br label %19
19: ; preds = %9, %6, %1
%20 = phi %struct.iovec* [ %18, %9 ], [ %4, %6 ], [ %4, %1 ]
%21 = load i32, i32* @h_errno
%22 = tail call i64 @hstrerror(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %19
%25 = load i32, i32* @h_errno
%26 = tail call i64 @hstrerror(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i32, i32* @h_errno
%29 = tail call i64 @hstrerror(i32 %28)
%30 = inttoptr i64 %29 to i8*
%31 = load i8, i8* %30
%32 = tail call i8* @strchr(i8* dereferenceable(1) %27, i8 signext %31)
br label %33
33: ; preds = %19, %24
%34 = phi i8* [ %32, %24 ], [ null, %19 ]
%35 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i64 0, i32 0
store i8* %34, i8** %35
%36 = tail call i8* @strlen(i8* %34)
%37 = ptrtoint i8* %36 to i64
%38 = trunc i64 %37 to i32
%39 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i64 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i64 1
%41 = getelementptr inbounds %struct.iovec, %struct.iovec* %40, i64 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %41
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i64 1, i32 1
store i32 1, i32* %42
%43 = load i32, i32* @STDERR_FILENO
%44 = ptrtoint %struct.iovec* %40 to i64
%45 = ptrtoint [4 x %struct.iovec]* %2 to i64
%46 = sub i64 %44, %45
%47 = lshr exact i64 %46, 4
%48 = trunc i64 %47 to i32
%49 = add i32 %48, 1
%50 = call i32 @writev(i32 %43, %struct.iovec* %4, i32 %49)
ret void
}