#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 */
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int /*<<< orphan*/ strlcat(char *, char *, size_t);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
void errstr(int num, char *uprefix, char *buf, size_t len) {
  char *t;
  unsigned int uerr;
  char tmp[(20 + 2 + sizeof("Unknown error"))];
  t = tmp + sizeof(tmp);
  *--t = '\0';
  uerr = (num >= 0) ? num : -num;
  do {
    *--t = "0123456789"[uerr % 10];
  } while (uerr /= 10);
  if (num < 0)
    *--t = '-';
  *--t = ' ';
  *--t = ':';
  strlcpy(buf, uprefix, len);
  strlcat(buf, t, len);
}


x86 assembly (clang, -O0):
<errstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x50(%rbp),%rax
add    $0x24,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,-0x1(%rax)
cmpl   $0x0,-0x4(%rbp)
jl     116b <errstr+0x4b>
mov    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    1173 <errstr+0x53>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
mov    %eax,%ecx
lea    0xe70(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x2c(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    1179 <errstr+0x59>
cmpl   $0x0,-0x4(%rbp)
jge    11da <errstr+0xba>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2d,-0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x20,-0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x3a,-0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <strlcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strlcat@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errstr>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%eax
neg    %eax
cmovs  %edi,%eax
movb   $0x0,0x23(%rsp)
lea    0x22(%rsp),%rbx
mov    $0xcccccccd,%r8d
lea    0xeb3(%rip),%r9
nopl   (%rax)
mov    %eax,%ecx
imul   %r8,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%r10d
mov    %eax,%edx
sub    %r10d,%edx
movzbl (%rdx,%r9,1),%edx
mov    %dl,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    $0x9,%eax
mov    %ecx,%eax
ja     1150 <errstr+0x30>
test   %edi,%edi
js     1182 <errstr+0x62>
add    $0x1,%rbx
jmp    1185 <errstr+0x65>
movb   $0x2d,(%rbx)
movw   $0x203a,-0x2(%rbx)
add    $0xfffffffffffffffe,%rbx
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <strlcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strlcat@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define void @errstr(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [36 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = getelementptr inbounds [36 x i8], [36 x i8]* %11, i64 0, i64 0
%13 = getelementptr inbounds i8, i8* %12, i64 36
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = getelementptr inbounds i8, i8* %14, i32 -1
store i8* %15, i8** %9
store i8 0, i8* %15
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i32, i32* %5
br label %23
20: ; preds = %4
%21 = load i32, i32* %5
%22 = sub nsw i32 0, %21
br label %23
23: ; preds = %20, %18
%24 = phi i32 [ %19, %18 ], [ %22, %20 ]
store i32 %24, i32* %10
br label %25
25: ; preds = %33, %23
%26 = load i32, i32* %10
%27 = urem i32 %26, 10
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = load i8*, i8** %9
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %9
store i8 %30, i8* %32
br label %33
33: ; preds = %25
%34 = load i32, i32* %10
%35 = udiv i32 %34, 10
store i32 %35, i32* %10
%36 = icmp ne i32 %35, 0
br i1 %36, label %25, label %37
37: ; preds = %33
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %9
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %9
store i8 45, i8* %42
br label %43
43: ; preds = %40, %37
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i32 -1
store i8* %45, i8** %9
store i8 32, i8* %45
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i32 -1
store i8* %47, i8** %9
store i8 58, i8* %47
%48 = load i8*, i8** %7
%49 = load i8*, i8** %6
%50 = load i64, i64* %8
%51 = call i32 @strlcpy(i8* %48, i8* %49, i64 %50)
%52 = load i8*, i8** %7
%53 = load i8*, i8** %9
%54 = load i64, i64* %8
%55 = call i32 @strlcat(i8* %52, i8* %53, i64 %54)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define void @errstr(i32 %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca [36 x i8]
%6 = getelementptr inbounds [36 x i8], [36 x i8]* %5, i64 0, i64 0
%7 = getelementptr inbounds [36 x i8], [36 x i8]* %5, i64 0, i64 35
store i8 0, i8* %7
%8 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
br label %9
9: ; preds = %9, %4
%10 = phi i8* [ %7, %4 ], [ %16, %9 ]
%11 = phi i32 [ %8, %4 ], [ %17, %9 ]
%12 = urem i32 %11, 10
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %10, i64 -1
store i8 %15, i8* %16
%17 = udiv i32 %11, 10
%18 = icmp ult i32 %11, 10
br i1 %18, label %19, label %9
19: ; preds = %9
%20 = icmp slt i32 %0, 0
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %10, i64 -2
store i8 45, i8* %22
br label %23
23: ; preds = %21, %19
%24 = phi i8* [ %22, %21 ], [ %16, %19 ]
%25 = getelementptr inbounds i8, i8* %24, i64 -1
store i8 32, i8* %25
%26 = getelementptr inbounds i8, i8* %24, i64 -2
store i8 58, i8* %26
%27 = tail call i32 @strlcpy(i8* %2, i8* %1, i64 %3)
%28 = call i32 @strlcat(i8* %2, i8* %26, i64 %3)
ret void
}