#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
size_t strnlen(char const *, int);
scalar_t__ strstr(char const *, char *);
int compute_exit_code(const char *status_msg) {
  if (!status_msg) {
    return 0;
  }
  size_t n = strnlen(status_msg, 2047);
  if (n >= 2047) {
    status_msg = "main: internal error: error message is too long";
    n = strnlen(status_msg, 2047);
  }
  fprintf(stderr, "%s\n", status_msg);
  return strstr(status_msg, "internal error:") ? 2 : 1;
}


x86 assembly (clang, -O0):
<compute_exit_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <compute_exit_code+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <compute_exit_code+0xa0>
mov    -0x10(%rbp),%rdi
mov    $0x7ff,%esi
call   1030 <strnlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x7ff,-0x18(%rbp)
jb     1190 <compute_exit_code+0x60>
lea    0xe86(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x7ff,%esi
call   1030 <strnlen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,%rdx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_exit_code>:
test   %rdi,%rdi
je     1194 <compute_exit_code+0x64>
push   %rbx
mov    %rdi,%rbx
mov    $0x7ff,%esi
call   1030 <strnlen@plt>
cmp    $0x7ff,%rax
jb     115f <compute_exit_code+0x2f>
lea    0xeae(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7ff,%esi
call   1030 <strnlen@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xec1(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
cmp    $0x1,%rax
mov    $0x2,%eax
sbb    $0x0,%eax
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [48 x i8] c"main: internal error: error message is too long\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [16 x i8] c"internal error:\00"
define i32 @compute_exit_code(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %25
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strnlen(i8* %9, i32 2047)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = icmp uge i64 %11, 2047
br i1 %12, label %13, label %16
13: ; preds = %8
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8** %3
%14 = load i8*, i8** %3
%15 = call i64 @strnlen(i8* %14, i32 2047)
store i64 %15, i64* %4
br label %16
16: ; preds = %13, %8
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %3
%21 = call i64 @strstr(i8* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 2, i32 1
store i32 %24, i32* %2
br label %25
25: ; preds = %16, %7
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [48 x i8] c"main: internal error: error message is too long\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [16 x i8] c"internal error:\00"
define i32 @compute_exit_code(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = tail call i64 @strnlen(i8* %0, i32 2047)
%5 = icmp ugt i64 %4, 2046
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i64 @strnlen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 2047)
br label %8
8: ; preds = %6, %3
%9 = phi i8* [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), %6 ], [ %0, %3 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = tail call i64 @strstr(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i32 1, i32 2
br label %15
15: ; preds = %1, %8
%16 = phi i32 [ %14, %8 ], [ 0, %1 ]
ret i32 %16
}