#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 */
typedef int /*<<< orphan*/ substrings;

/* Variables and functions */
scalar_t__ sqlite3StrNICmp(char const *, char const *, int);
int tolower(int);
char sqlite3AffinityType(const char *zType, int nType) {
  int n, i;
  static const struct {
    const char *zSub;
    char nSub;
    char affinity;
  } substrings[] = {
      {"INT", 3, 'i'},  {"CHAR", 4, 't'}, {"CLOB", 4, 't'},
      {"TEXT", 4, 't'}, {"BLOB", 4, 'o'},
  };
  if (nType == 0) {
    return 'o';
  }
  for (i = 0; i < sizeof(substrings) / sizeof(substrings[0]); i++) {
    int c1 = substrings[i].zSub[0];
    int c2 = tolower(c1);
    int limit = nType - substrings[i].nSub;
    const char *z = substrings[i].zSub;
    for (n = 0; n <= limit; n++) {
      int c = zType[n];
      if ((c == c1 || c == c2) &&
          0 == sqlite3StrNICmp(&zType[n], z, substrings[i].nSub)) {
        return substrings[i].affinity;
      }
    }
  }
  return 'n';
}


x86 assembly (clang, -O0):
<sqlite3AffinityType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1142 <sqlite3AffinityType+0x22>
movb   $0x6f,-0x1(%rbp)
jmp    126d <sqlite3AffinityType+0x14d>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x5,%rax
jae    1269 <sqlite3AffinityType+0x149>
movslq -0x1c(%rbp),%rcx
lea    0x2c6e(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
movslq -0x1c(%rbp),%rdx
lea    0x2c45(%rip),%rcx
shl    $0x4,%rdx
add    %rdx,%rcx
movsbl 0x8(%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
movslq -0x1c(%rbp),%rcx
lea    0x2c2a(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     1256 <sqlite3AffinityType+0x136>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11ee <sqlite3AffinityType+0xce>
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1243 <sqlite3AffinityType+0x123>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rcx
lea    0x2bc8(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movsbl 0x8(%rax),%edx
call   1040 <sqlite3StrNICmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1243 <sqlite3AffinityType+0x123>
movslq -0x1c(%rbp),%rcx
lea    0x2b9f(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x9(%rax),%al
mov    %al,-0x1(%rbp)
jmp    126d <sqlite3AffinityType+0x14d>
jmp    1248 <sqlite3AffinityType+0x128>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <sqlite3AffinityType+0x9b>
jmp    125b <sqlite3AffinityType+0x13b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <sqlite3AffinityType+0x29>
movb   $0x6e,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3AffinityType>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     118e <sqlite3AffinityType+0x6e>
mov    %esi,%r12d
mov    %rdi,%r15
mov    $0x49,%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
mov    $0x6e,%al
cmp    $0x3,%r12d
jl     1318 <sqlite3AffinityType+0x1f8>
lea    -0x2(%r12),%r14d
lea    0xea7(%rip),%r13
mov    %r15,%rbp
jmp    117f <sqlite3AffinityType+0x5f>
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1040 <sqlite3StrNICmp@plt>
test   %rax,%rax
je     11f2 <sqlite3AffinityType+0xd2>
add    $0x1,%rbp
add    $0xffffffffffffffff,%r14
je     1195 <sqlite3AffinityType+0x75>
movsbl 0x0(%rbp),%eax
cmp    $0x49,%eax
je     1160 <sqlite3AffinityType+0x40>
cmp    %eax,%ebx
jne    1175 <sqlite3AffinityType+0x55>
jmp    1160 <sqlite3AffinityType+0x40>
mov    $0x6f,%al
jmp    1318 <sqlite3AffinityType+0x1f8>
mov    $0x43,%edi
call   1030 <tolower@plt>
cmp    $0x4,%r12d
jl     1209 <sqlite3AffinityType+0xe9>
mov    %eax,%ebx
lea    -0x3(%r12),%r13d
mov    %r15,%rbp
mov    %r13,%r14
jmp    11e3 <sqlite3AffinityType+0xc3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
lea    0xe3a(%rip),%rsi
mov    $0x4,%edx
call   1040 <sqlite3StrNICmp@plt>
test   %rax,%rax
je     1210 <sqlite3AffinityType+0xf0>
add    $0x1,%rbp
add    $0xffffffffffffffff,%r14
je     11f9 <sqlite3AffinityType+0xd9>
movsbl 0x0(%rbp),%eax
cmp    $0x43,%eax
je     11c0 <sqlite3AffinityType+0xa0>
cmp    %eax,%ebx
jne    11d9 <sqlite3AffinityType+0xb9>
jmp    11c0 <sqlite3AffinityType+0xa0>
xor    %ecx,%ecx
jmp    1309 <sqlite3AffinityType+0x1e9>
mov    $0x43,%edi
call   1030 <tolower@plt>
cmp    $0x4,%r12d
jge    121a <sqlite3AffinityType+0xfa>
mov    $0x6e,%al
jmp    1318 <sqlite3AffinityType+0x1f8>
mov    $0x1,%ecx
jmp    1309 <sqlite3AffinityType+0x1e9>
mov    %eax,%r14d
lea    0xde5(%rip),%r12
mov    %r15,%rbp
mov    %r13,%rbx
jmp    1253 <sqlite3AffinityType+0x133>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <sqlite3StrNICmp@plt>
test   %rax,%rax
je     12f6 <sqlite3AffinityType+0x1d6>
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     1263 <sqlite3AffinityType+0x143>
movsbl 0x0(%rbp),%eax
cmp    $0x43,%eax
je     1230 <sqlite3AffinityType+0x110>
cmp    %eax,%r14d
jne    1249 <sqlite3AffinityType+0x129>
jmp    1230 <sqlite3AffinityType+0x110>
mov    $0x54,%edi
call   1030 <tolower@plt>
mov    %eax,%r14d
lea    0xd97(%rip),%r12
mov    %r15,%rbp
mov    %r13,%rbx
jmp    129f <sqlite3AffinityType+0x17f>
nop
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <sqlite3StrNICmp@plt>
test   %rax,%rax
je     12fd <sqlite3AffinityType+0x1dd>
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     12af <sqlite3AffinityType+0x18f>
movsbl 0x0(%rbp),%eax
cmp    $0x54,%eax
je     1280 <sqlite3AffinityType+0x160>
cmp    %eax,%r14d
jne    1295 <sqlite3AffinityType+0x175>
jmp    1280 <sqlite3AffinityType+0x160>
mov    $0x42,%edi
call   1030 <tolower@plt>
mov    %eax,%ebx
lea    0xd51(%rip),%rbp
jmp    12e7 <sqlite3AffinityType+0x1c7>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <sqlite3StrNICmp@plt>
test   %rax,%rax
je     1304 <sqlite3AffinityType+0x1e4>
add    $0x1,%r15
add    $0xffffffffffffffff,%r13
je     1209 <sqlite3AffinityType+0xe9>
movsbl (%r15),%eax
cmp    $0x42,%eax
je     12c4 <sqlite3AffinityType+0x1a4>
cmp    %eax,%ebx
jne    12d9 <sqlite3AffinityType+0x1b9>
jmp    12c4 <sqlite3AffinityType+0x1a4>
mov    $0x2,%ecx
jmp    1309 <sqlite3AffinityType+0x1e9>
mov    $0x3,%ecx
jmp    1309 <sqlite3AffinityType+0x1e9>
mov    $0x4,%ecx
shl    $0x4,%rcx
lea    0x2abc(%rip),%rax
mov    0x9(%rcx,%rax,1),%al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i8, i8 }
@sqlite3AffinityType.substrings = internal constant [5 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8 3, i8 105 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8 4, i8 111 }]
@.str = [4 x i8] c"INT\00"
@.str.1 = [5 x i8] c"CHAR\00"
@.str.2 = [5 x i8] c"CLOB\00"
@.str.3 = [5 x i8] c"TEXT\00"
@.str.4 = [5 x i8] c"BLOB\00"
define signext i8 @sqlite3AffinityType(i8* %0, i32 %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i8 111, i8* %3
br label %92
16: ; preds = %2
store i32 0, i32* %7
br label %17
17: ; preds = %88, %16
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = icmp ult i64 %19, 5
br i1 %20, label %21, label %91
21: ; preds = %17
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %23
%25 = getelementptr inbounds %struct.anon, %struct.anon* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = call i32 @tolower(i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %5
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %34
%36 = getelementptr inbounds %struct.anon, %struct.anon* %35, i32 0, i32 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %32, %38
store i32 %39, i32* %10
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %41
%43 = getelementptr inbounds %struct.anon, %struct.anon* %42, i32 0, i32 0
%44 = load i8*, i8** %43
store i8* %44, i8** %11
store i32 0, i32* %6
br label %45
45: ; preds = %84, %21
%46 = load i32, i32* %6
%47 = load i32, i32* %10
%48 = icmp sle i32 %46, %47
br i1 %48, label %49, label %87
49: ; preds = %45
%50 = load i8*, i8** %4
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
store i32 %55, i32* %12
%56 = load i32, i32* %12
%57 = load i32, i32* %8
%58 = icmp eq i32 %56, %57
br i1 %58, label %63, label %59
59: ; preds = %49
%60 = load i32, i32* %12
%61 = load i32, i32* %9
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %83
63: ; preds = %59, %49
%64 = load i8*, i8** %4
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8*, i8** %11
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %70
%72 = getelementptr inbounds %struct.anon, %struct.anon* %71, i32 0, i32 1
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = call i64 @sqlite3StrNICmp(i8* %67, i8* %68, i32 %74)
%76 = icmp eq i64 0, %75
br i1 %76, label %77, label %83
77: ; preds = %63
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %79
%81 = getelementptr inbounds %struct.anon, %struct.anon* %80, i32 0, i32 2
%82 = load i8, i8* %81
store i8 %82, i8* %3
br label %92
83: ; preds = %63, %59
br label %84
84: ; preds = %83
%85 = load i32, i32* %6
%86 = add nsw i32 %85, 1
store i32 %86, i32* %6
br label %45
87: ; preds = %45
br label %88
88: ; preds = %87
%89 = load i32, i32* %7
%90 = add nsw i32 %89, 1
store i32 %90, i32* %7
br label %17
91: ; preds = %17
store i8 110, i8* %3
br label %92
92: ; preds = %91, %77, %15
%93 = load i8, i8* %3
ret i8 %93
}

LLVM IR (-O2):
%struct.anon = type { i8*, i8, i8 }
@sqlite3AffinityType.substrings = internal unnamed_addr constant [5 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8 3, i8 105 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8 4, i8 116 }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8 4, i8 111 }]
@.str = [4 x i8] c"INT\00"
@.str.1 = [5 x i8] c"CHAR\00"
@.str.2 = [5 x i8] c"CLOB\00"
@.str.3 = [5 x i8] c"TEXT\00"
@.str.4 = [5 x i8] c"BLOB\00"
define signext i8 @sqlite3AffinityType(i8* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %103, label %4
4: ; preds = %2
%5 = tail call i32 @tolower(i32 73)
%6 = icmp slt i32 %1, 3
br i1 %6, label %103, label %7
7: ; preds = %4
%8 = add nsw i32 %1, -2
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %21
%11 = phi i64 [ 0, %7 ], [ %22, %21 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 73
%15 = sext i8 %13 to i32
%16 = icmp eq i32 %5, %15
%17 = select i1 %14, i1 true, i1 %16
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = tail call i64 @sqlite3StrNICmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %10, %18
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, %9
br i1 %23, label %28, label %10
24: ; preds = %18, %42, %61, %79, %97
%25 = phi i64 [ 4, %97 ], [ 3, %79 ], [ 2, %61 ], [ 1, %42 ], [ 0, %18 ]
%26 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @sqlite3AffinityType.substrings, i64 0, i64 %25, i32 2
%27 = load i8, i8* %26
br label %103
28: ; preds = %21
%29 = tail call i32 @tolower(i32 67)
%30 = icmp slt i32 %1, 4
br i1 %30, label %103, label %31
31: ; preds = %28
%32 = add nsw i32 %1, -3
%33 = zext i32 %32 to i64
br label %34
34: ; preds = %45, %31
%35 = phi i64 [ 0, %31 ], [ %46, %45 ]
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 67
%39 = sext i8 %37 to i32
%40 = icmp eq i32 %29, %39
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = tail call i64 @sqlite3StrNICmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %24, label %45
45: ; preds = %42, %34
%46 = add nuw nsw i64 %35, 1
%47 = icmp eq i64 %46, %33
br i1 %47, label %48, label %34
48: ; preds = %45
%49 = tail call i32 @tolower(i32 67)
br i1 %30, label %103, label %50
50: ; preds = %48
%51 = add nsw i32 %1, -3
%52 = zext i32 %51 to i64
br label %53
53: ; preds = %64, %50
%54 = phi i64 [ 0, %50 ], [ %65, %64 ]
%55 = getelementptr inbounds i8, i8* %0, i64 %54
%56 = load i8, i8* %55
%57 = icmp eq i8 %56, 67
%58 = sext i8 %56 to i32
%59 = icmp eq i32 %49, %58
%60 = select i1 %57, i1 true, i1 %59
br i1 %60, label %61, label %64
61: ; preds = %53
%62 = tail call i64 @sqlite3StrNICmp(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%63 = icmp eq i64 %62, 0
br i1 %63, label %24, label %64
64: ; preds = %61, %53
%65 = add nuw nsw i64 %54, 1
%66 = icmp eq i64 %65, %52
br i1 %66, label %67, label %53
67: ; preds = %64
%68 = tail call i32 @tolower(i32 84)
%69 = add i32 %1, -3
%70 = zext i32 %69 to i64
br label %71
71: ; preds = %82, %67
%72 = phi i64 [ 0, %67 ], [ %83, %82 ]
%73 = getelementptr inbounds i8, i8* %0, i64 %72
%74 = load i8, i8* %73
%75 = icmp eq i8 %74, 84
%76 = sext i8 %74 to i32
%77 = icmp eq i32 %68, %76
%78 = select i1 %75, i1 true, i1 %77
br i1 %78, label %79, label %82
79: ; preds = %71
%80 = tail call i64 @sqlite3StrNICmp(i8* %73, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%81 = icmp eq i64 %80, 0
br i1 %81, label %24, label %82
82: ; preds = %79, %71
%83 = add nuw nsw i64 %72, 1
%84 = icmp eq i64 %83, %70
br i1 %84, label %85, label %71
85: ; preds = %82
%86 = tail call i32 @tolower(i32 66)
%87 = add i32 %1, -3
%88 = zext i32 %87 to i64
br label %89
89: ; preds = %100, %85
%90 = phi i64 [ 0, %85 ], [ %101, %100 ]
%91 = getelementptr inbounds i8, i8* %0, i64 %90
%92 = load i8, i8* %91
%93 = icmp eq i8 %92, 66
%94 = sext i8 %92 to i32
%95 = icmp eq i32 %86, %94
%96 = select i1 %93, i1 true, i1 %95
br i1 %96, label %97, label %100
97: ; preds = %89
%98 = tail call i64 @sqlite3StrNICmp(i8* %91, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%99 = icmp eq i64 %98, 0
br i1 %99, label %24, label %100
100: ; preds = %97, %89
%101 = add nuw nsw i64 %90, 1
%102 = icmp eq i64 %101, %88
br i1 %102, label %103, label %89
103: ; preds = %100, %4, %28, %48, %24, %2
%104 = phi i8 [ %27, %24 ], [ 111, %2 ], [ 110, %48 ], [ 110, %28 ], [ 110, %4 ], [ 110, %100 ]
ret i8 %104
}