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

/* Variables and functions */
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
scalar_t__ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/);
int /*<<< orphan*/ ERR_error_string_n(unsigned long, char *, int);
int /*<<< orphan*/ ERR_get_string_table();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ lh_ERR_STRING_DATA_node_stats_bio(int /*<<< orphan*/,
                                                     int /*<<< orphan*/ *);
int /*<<< orphan*/
lh_ERR_STRING_DATA_node_usage_stats_bio(int /*<<< orphan*/,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ lh_ERR_STRING_DATA_stats_bio(int /*<<< orphan*/,
                                                int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int errstr_main(int argc, char **argv) {
  int i, ret = 0;
  char buf[256];
  unsigned long l;
  SSL_load_error_strings();
  if ((argc > 1) && (strcmp(argv[1], "-stats") == 0)) {
    BIO *out = NULL;
    out = BIO_new(BIO_s_file());
    if ((out != NULL) && BIO_set_fp(out, stdout, BIO_NOCLOSE)) {
      lh_ERR_STRING_DATA_node_stats_bio(ERR_get_string_table(), out);
      lh_ERR_STRING_DATA_stats_bio(ERR_get_string_table(), out);
      lh_ERR_STRING_DATA_node_usage_stats_bio(ERR_get_string_table(), out);
    }
    if (out != NULL)
      BIO_free_all(out);
    argc--;
    argv++;
  }
  for (i = 1; i < argc; i++) {
    if (sscanf(argv[i], "%lx", &l)) {
      ERR_error_string_n(l, buf, sizeof buf);
      printf("%s\n", buf);
    } else {
      printf("%s: bad error code\n", argv[i]);
      printf("usage: errstr [-stats] <errno> ...\n");
      ret++;
    }
  }
  return (ret);
}


x86 assembly (clang, -O0):
<errstr_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <SSL_load_error_strings@plt>
cmpl   $0x1,-0x4(%rbp)
jle    12dc <errstr_main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12dc <errstr_main+0x10c>
movq   $0x0,-0x130(%rbp)
mov    $0x0,%al
call   10f0 <BIO_s_file@plt>
mov    %eax,%edi
call   1080 <BIO_new@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
je     12ad <errstr_main+0xdd>
mov    -0x130(%rbp),%rdi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
call   10a0 <BIO_set_fp@plt>
cmp    $0x0,%rax
je     12ad <errstr_main+0xdd>
mov    $0x0,%al
call   10e0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    -0x130(%rbp),%rsi
call   1030 <lh_ERR_STRING_DATA_node_stats_bio@plt>
mov    $0x0,%al
call   10e0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    -0x130(%rbp),%rsi
call   1050 <lh_ERR_STRING_DATA_stats_bio@plt>
mov    $0x0,%al
call   10e0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    -0x130(%rbp),%rsi
call   10d0 <lh_ERR_STRING_DATA_node_usage_stats_bio@plt>
cmpq   $0x0,-0x130(%rbp)
je     12c7 <errstr_main+0xf7>
mov    -0x130(%rbp),%rdi
call   10c0 <BIO_free_all@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    138e <errstr_main+0x1be>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd05(%rip),%rsi
lea    -0x128(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
je     134a <errstr_main+0x17a>
mov    -0x128(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <ERR_error_string_n@plt>
lea    -0x120(%rbp),%rsi
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    137b <errstr_main+0x1ab>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1380 <errstr_main+0x1b0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12e3 <errstr_main+0x113>
mov    -0x18(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<errstr_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   10c0 <SSL_load_error_strings@plt>
cmp    $0x2,%r14d
jl     133c <errstr_main+0x15c>
mov    0x8(%rbx),%rdi
lea    0xde5(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12b3 <errstr_main+0xd3>
movl   $0x0,0x4(%rsp)
xor    %eax,%eax
call   1100 <BIO_s_file@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
test   %rax,%rax
je     12a1 <errstr_main+0xc1>
mov    %rax,%rbp
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
call   10b0 <BIO_set_fp@plt>
test   %rax,%rax
je     1299 <errstr_main+0xb9>
xor    %eax,%eax
call   10f0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1030 <lh_ERR_STRING_DATA_node_stats_bio@plt>
xor    %eax,%eax
call   10f0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1060 <lh_ERR_STRING_DATA_stats_bio@plt>
xor    %eax,%eax
call   10f0 <ERR_get_string_table@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   10e0 <lh_ERR_STRING_DATA_node_usage_stats_bio@plt>
mov    %rbp,%rdi
call   10d0 <BIO_free_all@plt>
add    $0xffffffff,%r14d
cmp    $0x2,%r14d
jb     133c <errstr_main+0x15c>
add    $0x8,%rbx
mov    %r14d,%r13d
mov    $0x1,%r15d
lea    0xd44(%rip),%r14
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%r12
movl   $0x0,0x4(%rsp)
jmp    1303 <errstr_main+0x123>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1070 <ERR_error_string_n@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     133c <errstr_main+0x15c>
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   10a0 <sscanf@plt>
test   %rax,%rax
jne    12e0 <errstr_main+0x100>
mov    (%rbx,%r15,8),%rsi
lea    0xce9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcef(%rip),%rdi
call   1040 <puts@plt>
addl   $0x1,0x4(%rsp)
jmp    12fa <errstr_main+0x11a>
mov    0x4(%rsp),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"-stats\00"
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.1 = [4 x i8] c"%lx\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [20 x i8] c"%s: bad error code\0A\00"
@.str.4 = [36 x i8] c"usage: errstr [-stats] <errno> ...\0A\00"
define i32 @errstr_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i64
%9 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%10 = call i32 (...) @SSL_load_error_strings()
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %51
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %51
19: ; preds = %13
store i32* null, i32** %9
%20 = call i32 (...) @BIO_s_file()
%21 = call i32* @BIO_new(i32 %20)
store i32* %21, i32** %9
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %40
24: ; preds = %19
%25 = load i32*, i32** %9
%26 = load i32, i32* @stdout
%27 = load i32, i32* @BIO_NOCLOSE
%28 = call i64 @BIO_set_fp(i32* %25, i32 %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %24
%31 = call i32 (...) @ERR_get_string_table()
%32 = load i32*, i32** %9
%33 = call i32 @lh_ERR_STRING_DATA_node_stats_bio(i32 %31, i32* %32)
%34 = call i32 (...) @ERR_get_string_table()
%35 = load i32*, i32** %9
%36 = call i32 @lh_ERR_STRING_DATA_stats_bio(i32 %34, i32* %35)
%37 = call i32 (...) @ERR_get_string_table()
%38 = load i32*, i32** %9
%39 = call i32 @lh_ERR_STRING_DATA_node_usage_stats_bio(i32 %37, i32* %38)
br label %40
40: ; preds = %30, %24, %19
%41 = load i32*, i32** %9
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32*, i32** %9
%45 = call i32 @BIO_free_all(i32* %44)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %3
%48 = add nsw i32 %47, -1
store i32 %48, i32* %3
%49 = load i8**, i8*** %4
%50 = getelementptr inbounds i8*, i8** %49, i32 1
store i8** %50, i8*** %4
br label %51
51: ; preds = %46, %13, %2
store i32 1, i32* %5
br label %52
52: ; preds = %81, %51
%53 = load i32, i32* %5
%54 = load i32, i32* %3
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %84
56: ; preds = %52
%57 = load i8**, i8*** %4
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i64 @sscanf(i8* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %8)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %56
%65 = load i64, i64* %8
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%67 = call i32 @ERR_error_string_n(i64 %65, i8* %66, i32 256)
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %68)
br label %80
70: ; preds = %56
%71 = load i8**, i8*** %4
%72 = load i32, i32* %5
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 1
store i32 %79, i32* %6
br label %80
80: ; preds = %70, %64
br label %81
81: ; preds = %80
%82 = load i32, i32* %5
%83 = add nsw i32 %82, 1
store i32 %83, i32* %5
br label %52
84: ; preds = %52
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
@.str = [7 x i8] c"-stats\00"
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@.str.1 = [4 x i8] c"%lx\00"
@.str.3 = [20 x i8] c"%s: bad error code\0A\00"
@str = [35 x i8] c"usage: errstr [-stats] <errno> ...\00"
define i32 @errstr_main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 (...) @SSL_load_error_strings()
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %59
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %9
%15 = tail call i32 (...) @BIO_s_file()
%16 = tail call i32* @BIO_new(i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %32, label %18
18: ; preds = %14
%19 = load i32, i32* @stdout
%20 = load i32, i32* @BIO_NOCLOSE
%21 = tail call i64 @BIO_set_fp(i32* %16, i32 %19, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = tail call i32 (...) @ERR_get_string_table()
%25 = tail call i32 @lh_ERR_STRING_DATA_node_stats_bio(i32 %24, i32* %16)
%26 = tail call i32 (...) @ERR_get_string_table()
%27 = tail call i32 @lh_ERR_STRING_DATA_stats_bio(i32 %26, i32* %16)
%28 = tail call i32 (...) @ERR_get_string_table()
%29 = tail call i32 @lh_ERR_STRING_DATA_node_usage_stats_bio(i32 %28, i32* %16)
br label %30
30: ; preds = %18, %23
%31 = tail call i32 @BIO_free_all(i32* %16)
br label %32
32: ; preds = %30, %14
%33 = add nsw i32 %0, -1
%34 = icmp ugt i32 %33, 1
br i1 %34, label %35, label %59
35: ; preds = %9, %32
%36 = phi i8** [ %10, %32 ], [ %1, %9 ]
%37 = phi i32 [ %33, %32 ], [ %0, %9 ]
%38 = zext i32 %37 to i64
br label %39
39: ; preds = %35, %55
%40 = phi i64 [ 1, %35 ], [ %57, %55 ]
%41 = phi i32 [ 0, %35 ], [ %56, %55 ]
%42 = getelementptr inbounds i8*, i8** %36, i64 %40
%43 = load i8*, i8** %42
%44 = call i64 @sscanf(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %39
%47 = load i64, i64* %4
%48 = call i32 @ERR_error_string_n(i64 %47, i8* %5, i32 256)
%49 = call i32 @puts(i8* %5)
br label %55
50: ; preds = %39
%51 = load i8*, i8** %42
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%54 = add nsw i32 %41, 1
br label %55
55: ; preds = %46, %50
%56 = phi i32 [ %41, %46 ], [ %54, %50 ]
%57 = add nuw nsw i64 %40, 1
%58 = icmp eq i64 %57, %38
br i1 %58, label %59, label %39
59: ; preds = %55, %2, %32
%60 = phi i32 [ 0, %32 ], [ 0, %2 ], [ %56, %55 ]
ret i32 %60
}