#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 */

/* Variables and functions */
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ *strstr(char const *, char *);
int main(int argc, char *argv[]) {
  int i = 0;
  char prefix[64] = {0};
  for (; i < 255; ++i) {
    const char *errdesc = strerror(i);
    if (errdesc != NULL && strstr(errdesc, "Unknown error") == NULL) {
      fprintf(stdout, "%02d: %s\n", i, strerror(i));
      errno = i;
      sprintf(prefix, "by perror [%04d]", i);
      perror(prefix);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
cmpl   $0xff,-0x14(%rbp)
jge    1235 <main+0xd5>
mov    -0x14(%rbp),%edi
call   1070 <strerror@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1222 <main+0xc2>
mov    -0x68(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    1222 <main+0xc2>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    -0x6c(%rbp),%edx
mov    %rax,%rcx
lea    0xe19(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%ecx
mov    0x2ddc(%rip),%rax
mov    %ecx,(%rax)
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe04(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <perror@plt>
jmp    1227 <main+0xc7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x2d>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %ebx,%ebx
lea    0xe83(%rip),%r14
mov    0x2e5c(%rip),%r15
lea    0xe8d(%rip),%r12
mov    %rsp,%r13
jmp    119b <main+0x4b>
add    $0x1,%ebx
cmp    $0xff,%ebx
je     11f4 <main+0xa4>
mov    %ebx,%edi
call   1060 <strerror@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
jne    1190 <main+0x40>
mov    0x2e1a(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <strerror@plt>
mov    %ebp,%edi
lea    0xe3e(%rip),%rsi
mov    %ebx,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebx,(%r15)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
mov    %r13,%rdi
call   1040 <perror@plt>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Unknown error\00"
@stdout = global i32 0
@.str.1 = [10 x i8] c"%02d: %s\0A\00"
@errno = global i32 0
@.str.2 = [17 x i8] c"by perror [%04d]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = bitcast [64 x i8]* %7 to i8*
br label %10
10: ; preds = %35, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 255
br i1 %12, label %13, label %38
13: ; preds = %10
%14 = load i32, i32* %6
%15 = call i8* @strerror(i32 %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i8*, i8** %8
%20 = call i32* @strstr(i8* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i32, i32* @stdout
%24 = load i32, i32* %6
%25 = load i32, i32* %6
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24, i8* %26)
%28 = load i32, i32* %6
store i32 %28, i32* @errno
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%33 = call i32 @perror(i8* %32)
br label %34
34: ; preds = %22, %18, %13
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %10
38: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Unknown error\00"
@stdout = global i32 0
@.str.1 = [10 x i8] c"%02d: %s\0A\00"
@errno = global i32 0
@.str.2 = [17 x i8] c"by perror [%04d]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %18
%6 = phi i32 [ 0, %2 ], [ %19, %18 ]
%7 = tail call i8* @strerror(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %5
%10 = tail call i32* @strstr(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i32, i32* @stdout
%14 = tail call i8* @strerror(i32 %6)
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %6, i8* %14)
store i32 %6, i32* @errno
%16 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%17 = call i32 @perror(i8* %4)
br label %18
18: ; preds = %12, %9, %5
%19 = add nuw nsw i32 %6, 1
%20 = icmp eq i32 %19, 255
br i1 %20, label %21, label %5
21: ; preds = %18
ret i32 0
}