#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*/ failwith(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ strcmp(char *, char *);
void unexpected_termination(int argc, char **argv) {
  int sexp = 0;
  int i;
  for (i = 1; i < argc - 1; ++i) {
    if (strcmp(argv[i], "-protocol") == 0 && strcmp(argv[i + 1], "sexp") == 0)
      sexp = 1;
  }
  puts(sexp ? "((assoc) (class . \"failure\") (value . \"abnormal "
              "termination\") (notifications))"
            : "{\"class\": \"failure\", \"value\": \"abnormal termination\", "
              "\"notifications\": [] }");
  failwith("abnormal termination");
}


x86 assembly (clang, -O0):
<unexpected_termination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c1 <unexpected_termination+0x91>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ae <unexpected_termination+0x7e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ae <unexpected_termination+0x7e>
movl   $0x1,-0x14(%rbp)
jmp    11b3 <unexpected_termination+0x83>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <unexpected_termination+0x1d>
mov    -0x14(%rbp),%ecx
lea    0xe93(%rip),%rdi
lea    0xe3d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1040 <puts@plt>
lea    0xec5(%rip),%rdi
call   1030 <failwith@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unexpected_termination>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jl     11a9 <unexpected_termination+0x79>
mov    %rsi,%rbx
mov    %edi,%r14d
add    $0xffffffff,%r14d
xor    %ebp,%ebp
mov    $0x1,%r12d
lea    0xea7(%rip),%r15
jmp    1168 <unexpected_termination+0x38>
nopl   0x0(%rax,%rax,1)
mov    %r13,%r12
cmp    %r13,%r14
je     119c <unexpected_termination+0x6c>
mov    (%rbx,%r12,8),%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
lea    0x1(%r12),%r13
test   %rax,%rax
jne    1160 <unexpected_termination+0x30>
mov    0x8(%rbx,%r12,8),%rdi
lea    0xe80(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%ebp
jmp    1160 <unexpected_termination+0x30>
test   %ebp,%ebp
je     11a9 <unexpected_termination+0x79>
lea    0xe68(%rip),%rdi
jmp    11b0 <unexpected_termination+0x80>
lea    0xeae(%rip),%rdi
call   1040 <puts@plt>
lea    0xeee(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <failwith@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"-protocol\00"
@.str.1 = [5 x i8] c"sexp\00"
@.str.2 = [79 x i8] c"((assoc) (class . \22failure\22) (value . \22abnormal termination\22) (notifications))\00"
@.str.3 = [76 x i8] c"{\22class\22: \22failure\22, \22value\22: \22abnormal termination\22, \22notifications\22: [] }\00"
@.str.4 = [21 x i8] c"abnormal termination\00"
define void @unexpected_termination(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 1, i32* %6
br label %7
7: ; preds = %31, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %34
12: ; preds = %7
%13 = load i8**, i8*** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %12
%21 = load i8**, i8*** %4
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 1, i32* %5
br label %30
30: ; preds = %29, %20, %12
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %7
34: ; preds = %7
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0)
%39 = call i32 @puts(i8* %38)
%40 = call i32 @failwith(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"-protocol\00"
@.str.1 = [5 x i8] c"sexp\00"
@.str.2 = [79 x i8] c"((assoc) (class . \22failure\22) (value . \22abnormal termination\22) (notifications))\00"
@.str.3 = [76 x i8] c"{\22class\22: \22failure\22, \22value\22: \22abnormal termination\22, \22notifications\22: [] }\00"
@.str.4 = [21 x i8] c"abnormal termination\00"
define void @unexpected_termination(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = add nsw i32 %0, -1
%6 = zext i32 %5 to i64
br label %7
7: ; preds = %4, %21
%8 = phi i64 [ 1, %4 ], [ %14, %21 ]
%9 = phi i32 [ 0, %4 ], [ %22, %21 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %8
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = add nuw nsw i64 %8, 1
br i1 %13, label %15, label %21
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 %14
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 1, i32 %9
br label %21
21: ; preds = %7, %15
%22 = phi i32 [ %20, %15 ], [ %9, %7 ]
%23 = icmp eq i64 %14, %6
br i1 %23, label %24, label %7
24: ; preds = %21
%25 = icmp eq i32 %22, 0
br i1 %25, label %26, label %27
26: ; preds = %2, %24
br label %27
27: ; preds = %24, %26
%28 = phi i8* [ getelementptr inbounds ([76 x i8], [76 x i8]* @.str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([79 x i8], [79 x i8]* @.str.2, i64 0, i64 0), %24 ]
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
%30 = tail call i32 @failwith(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
ret void
}