#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 nif_check_integrity(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("USAGE: nif NIF\n");
    return -1;
  }
  int result = nif_check_integrity(argv[1]);
  switch (result) {
  case -10:
    printf("INVALID NIF: Invalid length\n");
    break;
  case 0:
    printf("INVALID NIF: Control letter test not passed\n");
    break;
  case 1:
    printf("VALID NIF\n");
    break;
  case -20:
    printf("INVALID NIF: Ill-formed NIF\n");
    break;
  default:
    printf("Unknown error\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1158 <main+0x38>
lea    0xf11(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <main+0xd4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <nif_check_integrity@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x14,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x15,%eax
ja     11d5 <main+0xb5>
mov    -0x20(%rbp),%rax
lea    0xe78(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
lea    0xef8(%rip),%rdi
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
lea    0xef2(%rip),%rdi
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
lea    0xefe(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <main+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jne    115e <main+0x3e>
mov    0x8(%rsi),%rdi
call   1040 <nif_check_integrity@plt>
add    $0x14,%eax
cmp    $0x15,%eax
ja     116e <main+0x4e>
xor    %ebx,%ebx
lea    0xf65(%rip),%rdi
lea    0xeb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xefc(%rip),%rdi
jmp    1165 <main+0x45>
lea    0xf6f(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xf51(%rip),%rdi
mov    $0xffffffff,%ebx
jmp    1165 <main+0x45>
lea    0xefb(%rip),%rdi
jmp    1165 <main+0x45>
lea    0xee8(%rip),%rdi
jmp    1165 <main+0x45>

LLVM IR (-O0):
@.str = [16 x i8] c"USAGE: nif NIF\0A\00"
@.str.1 = [29 x i8] c"INVALID NIF: Invalid length\0A\00"
@.str.2 = [45 x i8] c"INVALID NIF: Control letter test not passed\0A\00"
@.str.3 = [11 x i8] c"VALID NIF\0A\00"
@.str.4 = [29 x i8] c"INVALID NIF: Ill-formed NIF\0A\00"
@.str.5 = [15 x i8] c"Unknown error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @nif_check_integrity(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
switch i32 %16, label %25 [
i32 -10, label %17
i32 0, label %19
i32 1, label %21
i32 -20, label %23
]
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %27
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %27
21: ; preds = %11
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %27
23: ; preds = %11
%24 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %27
25: ; preds = %11
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
27: ; preds = %23, %21, %19, %17
store i32 0, i32* %3
br label %28
28: ; preds = %27, %25, %9
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@str = [28 x i8] c"INVALID NIF: Ill-formed NIF\00"
@str.6 = [10 x i8] c"VALID NIF\00"
@str.7 = [44 x i8] c"INVALID NIF: Control letter test not passed\00"
@str.8 = [28 x i8] c"INVALID NIF: Invalid length\00"
@str.9 = [14 x i8] c"Unknown error\00"
@str.10 = [15 x i8] c"USAGE: nif NIF\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @nif_check_integrity(i8* %6)
switch i32 %7, label %11 [
i32 -10, label %12
i32 0, label %8
i32 1, label %9
i32 -20, label %10
]
8: ; preds = %4
br label %12
9: ; preds = %4
br label %12
10: ; preds = %4
br label %12
11: ; preds = %4
br label %12
12: ; preds = %4, %2, %11, %10, %9, %8
%13 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0), %11 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0), %9 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.7, i64 0, i64 0), %8 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0), %2 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str.8, i64 0, i64 0), %4 ]
%14 = phi i32 [ -1, %11 ], [ 0, %10 ], [ 0, %9 ], [ 0, %8 ], [ -1, %2 ], [ 0, %4 ]
%15 = tail call i32 @puts(i8* dereferenceable(1) %13)
ret i32 %14
}