#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 */
char *dlr_error();
scalar_t__ errno;
int snprintf(char *, size_t, char *, char const *, char const *, ...);
char *strerror(scalar_t__);
int dlr_snprintf_pretty_error(char *str, size_t n, const char *context) {
  const char *dlr_err, *sys_err;
  int r;
  dlr_err = dlr_error();
  sys_err = (errno != 0) ? strerror(errno) : NULL;
  if (dlr_err == NULL && sys_err == NULL) {
    return 0;
  }
  if (dlr_err) {
    if (sys_err != NULL) {
      r = snprintf(str, n,
                   "DLRestrictions"
                   " error (%s): "
                   "%s (sys=%s)",
                   context, dlr_err, sys_err);
    } else {
      r = snprintf(str, n,
                   "DLRestrictions"
                   " error (%s): "
                   "%s",
                   context, dlr_err);
    }
  } else {
    r = snprintf(str, n,
                 "DLRestrictions"
                 " error (%s): "
                 "%s",
                 context, sys_err);
  }
  return r;
}


x86 assembly (clang, -O0):
<dlr_snprintf_pretty_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   1050 <dlr_error@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e8a(%rip),%rax
cmpq   $0x0,(%rax)
je     1178 <dlr_snprintf_pretty_error+0x48>
mov    0x2e79(%rip),%rax
mov    (%rax),%rdi
call   1040 <strerror@plt>
mov    %rax,-0x40(%rbp)
jmp    1183 <dlr_snprintf_pretty_error+0x53>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    1183 <dlr_snprintf_pretty_error+0x53>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ad <dlr_snprintf_pretty_error+0x7d>
cmpq   $0x0,-0x30(%rbp)
jne    11ad <dlr_snprintf_pretty_error+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    123a <dlr_snprintf_pretty_error+0x10a>
cmpq   $0x0,-0x28(%rbp)
je     1213 <dlr_snprintf_pretty_error+0xe3>
cmpq   $0x0,-0x30(%rbp)
je     11ed <dlr_snprintf_pretty_error+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
lea    0xe22(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    120e <dlr_snprintf_pretty_error+0xde>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe23(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1234 <dlr_snprintf_pretty_error+0x104>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xdfd(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dlr_snprintf_pretty_error>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <dlr_error@plt>
mov    %rax,%r13
mov    0x2e8b(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
je     1165 <dlr_snprintf_pretty_error+0x35>
call   1040 <strerror@plt>
mov    %rax,%rbx
mov    %r13,%rax
or     %rbx,%rax
jne    1179 <dlr_snprintf_pretty_error+0x49>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
test   %r13,%r13
je     11a9 <dlr_snprintf_pretty_error+0x79>
test   %rbx,%rbx
je     11be <dlr_snprintf_pretty_error+0x8e>
lea    0xe76(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    %r13,%r8
mov    %rbx,%r9
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>
lea    0xe77(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    %rbx,%r8
jmp    11d1 <dlr_snprintf_pretty_error+0xa1>
lea    0xe62(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    %r13,%r8
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [39 x i8] c"DLRestrictions error (%s): %s (sys=%s)\00"
@.str.1 = [30 x i8] c"DLRestrictions error (%s): %s\00"
define i32 @dlr_snprintf_pretty_error(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%11 = call i8* (...) @dlr_error()
store i8* %11, i8** %8
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
br label %18
17: ; preds = %3
br label %18
18: ; preds = %17, %14
%19 = phi i8* [ %16, %14 ], [ null, %17 ]
store i8* %19, i8** %9
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %4
br label %54
26: ; preds = %22, %18
%27 = load i8*, i8** %8
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %46
29: ; preds = %26
%30 = load i8*, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = load i64, i64* %6
%35 = load i8*, i8** %7
%36 = load i8*, i8** %8
%37 = load i8*, i8** %9
%38 = call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %33, i64 %34, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %35, i8* %36, i8* %37)
store i32 %38, i32* %10
br label %45
39: ; preds = %29
%40 = load i8*, i8** %5
%41 = load i64, i64* %6
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %40, i64 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %43)
store i32 %44, i32* %10
br label %45
45: ; preds = %39, %32
br label %52
46: ; preds = %26
%47 = load i8*, i8** %5
%48 = load i64, i64* %6
%49 = load i8*, i8** %7
%50 = load i8*, i8** %9
%51 = call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %47, i64 %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %49, i8* %50)
store i32 %51, i32* %10
br label %52
52: ; preds = %46, %45
%53 = load i32, i32* %10
store i32 %53, i32* %4
br label %54
54: ; preds = %52, %25
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [39 x i8] c"DLRestrictions error (%s): %s (sys=%s)\00"
@.str.1 = [30 x i8] c"DLRestrictions error (%s): %s\00"
define i32 @dlr_snprintf_pretty_error(i8* %0, i64 %1, i8* %2) {
%4 = tail call i8* (...) @dlr_error()
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i8* @strerror(i64 %5)
br label %9
9: ; preds = %3, %7
%10 = phi i8* [ %8, %7 ], [ null, %3 ]
%11 = icmp eq i8* %4, null
%12 = icmp eq i8* %10, null
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %22, label %14
14: ; preds = %9
br i1 %11, label %20, label %15
15: ; preds = %14
br i1 %12, label %18, label %16
16: ; preds = %15
%17 = tail call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %4, i8* %10)
br label %22
18: ; preds = %15
%19 = tail call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %4)
br label %22
20: ; preds = %14
%21 = tail call i32 (i8*, i64, i8*, i8*, i8*, ...) @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %10)
br label %22
22: ; preds = %20, %18, %16, %9
%23 = phi i32 [ 0, %9 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ]
ret i32 %23
}