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

/* Variables and functions */
int /*<<< orphan*/ _fail(char const *const, int const);
int /*<<< orphan*/ cm_print_error(char *, char const *const, ...);
int /*<<< orphan*/ strerror(int);
void _assert_return_code(const unsigned long int result, size_t rlen,
                         const unsigned long int error,
                         const char *const expression, const char *const file,
                         const int line) {
  unsigned long int valmax;
  switch (rlen) {
  case 1:
    valmax = 255;
    break;
  case 2:
    valmax = 32767;
    break;
  case 4:
    valmax = 2147483647;
    break;
  case 8:
  default:
    if (rlen > sizeof(valmax)) {
      valmax = 2147483647;
    } else {
      valmax = 9223372036854775807L;
    }
    break;
  }
  if (result > valmax - 1) {
    if (error > 0) {
      cm_print_error("%s < 0, errno(%"
                     "l"
                     "u"
                     "): %s\n",
                     expression, error, strerror((int)error));
    } else {
      cm_print_error("%s < 0\n", expression);
    }
    _fail(file, line);
  }
}


x86 assembly (clang, -O0):
<_assert_return_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
sub    $0x7,%rax
ja     11a6 <_assert_return_code+0x76>
mov    -0x40(%rbp),%rax
lea    0xe8f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0xff,-0x38(%rbp)
jmp    11d1 <_assert_return_code+0xa1>
movq   $0x7fff,-0x38(%rbp)
jmp    11d1 <_assert_return_code+0xa1>
movq   $0x7fffffff,-0x38(%rbp)
7f
jmp    11d1 <_assert_return_code+0xa1>
jmp    11a6 <_assert_return_code+0x76>
cmpq   $0x8,-0x10(%rbp)
jbe    11be <_assert_return_code+0x8e>
movq   $0x7fffffff,-0x38(%rbp)
7f
jmp    11cc <_assert_return_code+0x9c>
movabs $0x7fffffffffffffff,%rax
ff ff 7f
mov    %rax,-0x38(%rbp)
jmp    11d1 <_assert_return_code+0xa1>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jbe    1247 <_assert_return_code+0x117>
cmpq   $0x0,-0x18(%rbp)
jbe    1229 <_assert_return_code+0xf9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1050 <strerror@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <cm_print_error@plt>
jmp    123b <_assert_return_code+0x10b>
mov    -0x20(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <cm_print_error@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1040 <_fail@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_assert_return_code>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8,%r15
mov    %rcx,%rbp
mov    %rdx,%rbx
cmp    $0x1,%rsi
je     1161 <_assert_return_code+0x31>
cmp    $0x4,%rsi
je     116d <_assert_return_code+0x3d>
cmp    $0x2,%rsi
jne    1182 <_assert_return_code+0x52>
mov    $0x7ffe,%eax
cmp    %rdi,%rax
jae    1177 <_assert_return_code+0x47>
jmp    119e <_assert_return_code+0x6e>
mov    $0xfe,%eax
cmp    %rdi,%rax
jae    1177 <_assert_return_code+0x47>
jmp    119e <_assert_return_code+0x6e>
mov    $0x7ffffffe,%eax
cmp    %rdi,%rax
jb     119e <_assert_return_code+0x6e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x9,%rsi
mov    $0x7ffffffe,%ecx
movabs $0x7ffffffffffffffe,%rax
ff ff 7f
cmovae %rcx,%rax
cmp    %rdi,%rax
jae    1177 <_assert_return_code+0x47>
test   %rbx,%rbx
je     11c2 <_assert_return_code+0x92>
mov    %ebx,%edi
call   1050 <strerror@plt>
lea    0xe4f(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <cm_print_error@plt>
jmp    11d3 <_assert_return_code+0xa3>
lea    0xe4f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <cm_print_error@plt>
mov    %r15,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_fail@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"%s < 0, errno(%lu): %s\0A\00"
@.str.1 = [8 x i8] c"%s < 0\0A\00"
define void @_assert_return_code(i64 %0, i64 %1, i64 %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i64
store i64 %0, i64* %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i64, i64* %8
switch i64 %14, label %19 [
i64 1, label %15
i64 2, label %16
i64 4, label %17
i64 8, label %18
]
15: ; preds = %6
store i64 255, i64* %13
br label %25
16: ; preds = %6
store i64 32767, i64* %13
br label %25
17: ; preds = %6
store i64 2147483647, i64* %13
br label %25
18: ; preds = %6
br label %19
19: ; preds = %6, %18
%20 = load i64, i64* %8
%21 = icmp ugt i64 %20, 8
br i1 %21, label %22, label %23
22: ; preds = %19
store i64 2147483647, i64* %13
br label %24
23: ; preds = %19
store i64 9223372036854775807, i64* %13
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %17, %16, %15
%26 = load i64, i64* %7
%27 = load i64, i64* %13
%28 = sub i64 %27, 1
%29 = icmp ugt i64 %26, %28
br i1 %29, label %30, label %47
30: ; preds = %25
%31 = load i64, i64* %9
%32 = icmp ugt i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i8*, i8** %10
%35 = load i64, i64* %9
%36 = load i64, i64* %9
%37 = trunc i64 %36 to i32
%38 = call i32 @strerror(i32 %37)
%39 = call i32 (i8*, i8*, ...) @cm_print_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %34, i64 %35, i32 %38)
br label %43
40: ; preds = %30
%41 = load i8*, i8** %10
%42 = call i32 (i8*, i8*, ...) @cm_print_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %33
%44 = load i8*, i8** %11
%45 = load i32, i32* %12
%46 = call i32 @_fail(i8* %44, i32 %45)
br label %47
47: ; preds = %43, %25
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"%s < 0, errno(%lu): %s\0A\00"
@.str.1 = [8 x i8] c"%s < 0\0A\00"
define void @_assert_return_code(i64 %0, i64 %1, i64 %2, i8* %3, i8* %4, i32 %5) {
switch i64 %1, label %9 [
i64 1, label %12
i64 2, label %7
i64 4, label %8
]
7: ; preds = %6
br label %12
8: ; preds = %6
br label %12
9: ; preds = %6
%10 = icmp ugt i64 %1, 8
%11 = select i1 %10, i64 2147483646, i64 9223372036854775806
br label %12
12: ; preds = %9, %6, %8, %7
%13 = phi i64 [ 2147483646, %8 ], [ 32766, %7 ], [ 254, %6 ], [ %11, %9 ]
%14 = icmp ult i64 %13, %0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = icmp eq i64 %2, 0
br i1 %16, label %21, label %17
17: ; preds = %15
%18 = trunc i64 %2 to i32
%19 = tail call i32 @strerror(i32 %18)
%20 = tail call i32 (i8*, i8*, ...) @cm_print_error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %3, i64 %2, i32 %19)
br label %23
21: ; preds = %15
%22 = tail call i32 (i8*, i8*, ...) @cm_print_error(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %23
23: ; preds = %21, %17
%24 = tail call i32 @_fail(i8* %4, i32 %5)
br label %25
25: ; preds = %23, %12
ret void
}