#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 */
unsigned char digito_verificador(char *, int const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
char *to_upper_case_and_convert(unsigned char *);
unsigned char verifica_rfc(const char *rfc, const int debug) {
  unsigned char result = 0;
  char copy[13];
  char *buffer = 0;
  size_t len = 0;
  buffer = to_upper_case_and_convert((unsigned char *)rfc);
  len = strlen(buffer);
  if (len > 13) {
    fprintf(stderr,
            "digito_verificador: Error. La clave del R.F.C., sin su dígito "
            "verificador, no debe exceder 12 carácteres. La cantidad de "
            "carácteres en la clave del R.F.C. a verificar, sin el dígito "
            "verificador fue: %d.\n",
            len);
    free(buffer);
    return 100;
  } else if (len < 12) {
    fprintf(stderr,
            "digito_verificador: Error. La clave del R.F.C. a verificar, debe "
            "contener al menos 11 carácteres, sin su dígito verificador (al "
            "menos para personas morales.) El número de carácteres en la clave "
            "a verificar fue: %d.\n",
            len);
    free(buffer);
    return 100;
  }
  memset(copy, 0, 13);
  memcpy(copy, buffer, len - 1);
  result = digito_verificador(copy, debug);
  if (result == buffer[len - 1])
    result = 0;
  free(buffer);
  return result;
}


x86 assembly (clang, -O0):
<verifica_rfc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <to_upper_case_and_convert@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0xd,-0x38(%rbp)
jbe    11e3 <verifica_rfc+0x73>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movb   $0x64,-0x1(%rbp)
jmp    1281 <verifica_rfc+0x111>
cmpq   $0xc,-0x38(%rbp)
jae    1219 <verifica_rfc+0xa9>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xece(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movb   $0x64,-0x1(%rbp)
jmp    1281 <verifica_rfc+0x111>
jmp    121e <verifica_rfc+0xae>
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1050 <memset@plt>
lea    -0x22(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
sub    $0x1,%rdx
call   1080 <memcpy@plt>
lea    -0x22(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <digito_verificador@plt>
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdx
sub    $0x1,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1272 <verifica_rfc+0x102>
movb   $0x0,-0x15(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x15(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verifica_rfc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
call   1090 <to_upper_case_and_convert@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
cmp    $0xe,%rax
jb     11a9 <verifica_rfc+0x39>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
jmp    11bf <verifica_rfc+0x4f>
cmp    $0xb,%rbx
ja     11d4 <verifica_rfc+0x64>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xf11(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x64,%bpl
jmp    121e <verifica_rfc+0xae>
lea    0x3(%rsp),%r15
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xd,%edx
call   1050 <memset@plt>
mov    %rbx,%rdx
add    $0xffffffffffffffff,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <memcpy@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <digito_verificador@plt>
movzbl %al,%ebp
movsbl -0x1(%r14,%rbx,1),%eax
cmp    %eax,%ebp
cmove  %r12d,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [208 x i8] c"digito_verificador: Error. La clave del R.F.C., sin su d\C3\ADgito verificador, no debe exceder 12 car\C3\A1cteres. La cantidad de car\C3\A1cteres en la clave del R.F.C. a verificar, sin el d\C3\ADgito verificador fue: %d.\0A\00"
@.str.1 = [220 x i8] c"digito_verificador: Error. La clave del R.F.C. a verificar, debe contener al menos 11 car\C3\A1cteres, sin su d\C3\ADgito verificador (al menos para personas morales.) El n\C3\BAmero de car\C3\A1cteres en la clave a verificar fue: %d.\0A\00"
define zeroext i8 @verifica_rfc(i8* %0, i32 %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = alloca [13 x i8]
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8 0, i8* %6
store i8* null, i8** %8
store i64 0, i64* %9
%10 = load i8*, i8** %4
%11 = call i8* @to_upper_case_and_convert(i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %9
%14 = load i64, i64* %9
%15 = icmp ugt i64 %14, 13
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i64, i64* %9
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([208 x i8], [208 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = load i8*, i8** %8
%21 = call i32 @free(i8* %20)
store i8 100, i8* %3
br label %57
22: ; preds = %2
%23 = load i64, i64* %9
%24 = icmp ult i64 %23, 12
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i64, i64* %9
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
store i8 100, i8* %3
br label %57
31: ; preds = %22
br label %32
32: ; preds = %31
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i32 0, i32 13)
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %8
%37 = load i64, i64* %9
%38 = sub i64 %37, 1
%39 = call i32 @memcpy(i8* %35, i8* %36, i64 %38)
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %5
%42 = call zeroext i8 @digito_verificador(i8* %40, i32 %41)
store i8 %42, i8* %6
%43 = load i8, i8* %6
%44 = zext i8 %43 to i32
%45 = load i8*, i8** %8
%46 = load i64, i64* %9
%47 = sub i64 %46, 1
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %44, %50
br i1 %51, label %52, label %53
52: ; preds = %32
store i8 0, i8* %6
br label %53
53: ; preds = %52, %32
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
%56 = load i8, i8* %6
store i8 %56, i8* %3
br label %57
57: ; preds = %53, %25, %16
%58 = load i8, i8* %3
ret i8 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [208 x i8] c"digito_verificador: Error. La clave del R.F.C., sin su d\C3\ADgito verificador, no debe exceder 12 car\C3\A1cteres. La cantidad de car\C3\A1cteres en la clave del R.F.C. a verificar, sin el d\C3\ADgito verificador fue: %d.\0A\00"
@.str.1 = [220 x i8] c"digito_verificador: Error. La clave del R.F.C. a verificar, debe contener al menos 11 car\C3\A1cteres, sin su d\C3\ADgito verificador (al menos para personas morales.) El n\C3\BAmero de car\C3\A1cteres en la clave a verificar fue: %d.\0A\00"
define zeroext i8 @verifica_rfc(i8* %0, i32 %1) {
%3 = alloca [13 x i8]
%4 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @to_upper_case_and_convert(i8* %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = icmp ugt i64 %6, 13
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([208 x i8], [208 x i8]* @.str, i64 0, i64 0), i64 %6)
%11 = tail call i32 @free(i8* %5)
br label %30
12: ; preds = %2
%13 = icmp ult i64 %6, 12
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([220 x i8], [220 x i8]* @.str.1, i64 0, i64 0), i64 %6)
%17 = tail call i32 @free(i8* %5)
br label %30
18: ; preds = %12
%19 = call i32 @memset(i8* %4, i32 0, i32 13)
%20 = add nsw i64 %6, -1
%21 = call i32 @memcpy(i8* %4, i8* %5, i64 %20)
%22 = call zeroext i8 @digito_verificador(i8* %4, i32 %1)
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds i8, i8* %5, i64 %20
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %23, %26
%28 = select i1 %27, i8 0, i8 %22
%29 = call i32 @free(i8* %5)
br label %30
30: ; preds = %18, %14, %8
%31 = phi i8 [ 100, %8 ], [ 100, %14 ], [ %28, %18 ]
ret i8 %31
}