#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 const control_letter(int);
long prepare_nif(char const *);
size_t strlen(char const *);
int nif_check_integrity(const char *nif) {
  size_t nif_size = strlen(nif);
  if (nif_size != 9) {
    return -10;
  }
  long int num_nif = prepare_nif(nif);
  if (num_nif == -20) {
    return -20;
  }
  int rest = num_nif % 23;
  return nif[8] == control_letter(rest) ? 1 : 0;
}


x86 assembly (clang, -O0):
<nif_check_integrity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x9,-0x18(%rbp)
je     1160 <nif_check_integrity+0x30>
movl   $0xfffffff6,-0x4(%rbp)
jmp    11bf <nif_check_integrity+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <prepare_nif@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffec,-0x20(%rbp)
jne    1184 <nif_check_integrity+0x54>
movl   $0xffffffec,-0x4(%rbp)
jmp    11bf <nif_check_integrity+0x8f>
mov    -0x20(%rbp),%rax
mov    $0x17,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x8(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <control_letter@plt>
mov    -0x28(%rbp),%edx
movsbl %al,%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nif_check_integrity>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    $0xfffffff6,%eax
cmp    $0x9,%rcx
jne    119b <nif_check_integrity+0x6b>
mov    %rbx,%rdi
call   1030 <prepare_nif@plt>
mov    %rax,%rcx
mov    $0xffffffec,%eax
cmp    $0xffffffffffffffec,%rcx
je     119b <nif_check_integrity+0x6b>
movabs $0xb21642c8590b2165,%rdx
42 16 b2
mov    %rcx,%rax
imul   %rdx
mov    %rcx,%rdi
add    %rdx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
shr    $0x4,%rdi
add    %eax,%edi
lea    (%rdi,%rdi,2),%eax
shl    $0x3,%eax
sub    %eax,%edi
add    %ecx,%edi
mov    0x8(%rbx),%bl
call   1050 <control_letter@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %cl,%bl
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
define i32 @nif_check_integrity(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp ne i64 %9, 9
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -10, i32* %2
br label %32
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @prepare_nif(i8* %13)
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = icmp eq i64 %15, -20
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 -20, i32* %2
br label %32
18: ; preds = %12
%19 = load i64, i64* %5
%20 = srem i64 %19, 23
%21 = trunc i64 %20 to i32
store i32 %21, i32* %6
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i32, i32* %6
%27 = call signext i8 @control_letter(i32 %26)
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %25, %28
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 1, i32 0
store i32 %31, i32* %2
br label %32
32: ; preds = %18, %17, %11
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @nif_check_integrity(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp eq i64 %2, 9
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call i64 @prepare_nif(i8* %0)
%6 = icmp eq i64 %5, -20
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = srem i64 %5, 23
%9 = trunc i64 %8 to i32
%10 = getelementptr inbounds i8, i8* %0, i64 8
%11 = load i8, i8* %10
%12 = tail call signext i8 @control_letter(i32 %9)
%13 = icmp eq i8 %11, %12
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %7, %4, %1
%16 = phi i32 [ -10, %1 ], [ %14, %7 ], [ -20, %4 ]
ret i32 %16
}