#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*/ sqlite3;

/* Variables and functions */
int sqlite_delegate_address(int /*<<< orphan*/ *, char *, char *);
int sqlite_delegate_user(int /*<<< orphan*/ *, char *, char *);
int sqlite_get_delegated(int /*<<< orphan*/ *, char *);
int sqlite_get_delegated_addresses(int /*<<< orphan*/ *, char *);
int sqlite_get_delegated_users(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int mode_delegate(sqlite3 *db, int argc, char **argv) {
  int status = 0;
  if (argc < 2) {
    status = sqlite_get_delegated(db, "%");
  } else if (!strcmp(argv[1], "address")) {
    if (argc < 3) {
      status = sqlite_get_delegated_addresses(db, "%");
    } else if (argc < 4) {
      status = sqlite_get_delegated_addresses(db, argv[2]);
    } else {
      status = sqlite_delegate_address(db, argv[2], argv[3]);
    }
  } else if (!strcmp(argv[1], "user")) {
    if (argc < 3) {
      status = sqlite_get_delegated_users(db, "%");
    } else if (argc < 4) {
      status = sqlite_get_delegated_users(db, argv[2]);
    } else {
      status = sqlite_delegate_user(db, argv[2], argv[3]);
    }
  } else {
    status = sqlite_get_delegated(db, argv[1]);
  }
  return status;
}


x86 assembly (clang, -O0):
<mode_delegate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    119c <mode_delegate+0x3c>
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1030 <sqlite_get_delegated@plt>
mov    %eax,-0x1c(%rbp)
jmp    12ca <mode_delegate+0x16a>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1224 <mode_delegate+0xc4>
cmpl   $0x3,-0xc(%rbp)
jge    11db <mode_delegate+0x7b>
mov    -0x8(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1050 <sqlite_get_delegated_addresses@plt>
mov    %eax,-0x1c(%rbp)
jmp    121f <mode_delegate+0xbf>
cmpl   $0x4,-0xc(%rbp)
jge    11fe <mode_delegate+0x9e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <sqlite_get_delegated_addresses@plt>
mov    %eax,-0x1c(%rbp)
jmp    121a <mode_delegate+0xba>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdx
call   1080 <sqlite_delegate_address@plt>
mov    %eax,-0x1c(%rbp)
jmp    121f <mode_delegate+0xbf>
jmp    12c5 <mode_delegate+0x165>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd7(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12ac <mode_delegate+0x14c>
cmpl   $0x3,-0xc(%rbp)
jge    1263 <mode_delegate+0x103>
mov    -0x8(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <sqlite_get_delegated_users@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a7 <mode_delegate+0x147>
cmpl   $0x4,-0xc(%rbp)
jge    1286 <mode_delegate+0x126>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <sqlite_get_delegated_users@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a2 <mode_delegate+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdx
call   1060 <sqlite_delegate_user@plt>
mov    %eax,-0x1c(%rbp)
jmp    12a7 <mode_delegate+0x147>
jmp    12c0 <mode_delegate+0x160>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <sqlite_get_delegated@plt>
mov    %eax,-0x1c(%rbp)
jmp    12c5 <mode_delegate+0x165>
jmp    12ca <mode_delegate+0x16a>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_delegate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
cmp    $0x1,%esi
jg     117b <mode_delegate+0x1b>
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
jmp    11b0 <mode_delegate+0x50>
mov    %rdx,%r14
mov    %esi,%ebp
mov    0x8(%rdx),%rbx
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11bf <mode_delegate+0x5f>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11cd <mode_delegate+0x6d>
mov    %r15,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sqlite_get_delegated@plt>
cmp    $0x2,%ebp
ja     11db <mode_delegate+0x7b>
lea    0xe35(%rip),%rsi
jmp    11e4 <mode_delegate+0x84>
cmp    $0x2,%ebp
ja     11f6 <mode_delegate+0x96>
lea    0xe27(%rip),%rsi
jmp    11ff <mode_delegate+0x9f>
mov    0x10(%r14),%rsi
cmp    $0x3,%ebp
jne    1211 <mode_delegate+0xb1>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sqlite_get_delegated_addresses@plt>
mov    0x10(%r14),%rsi
cmp    $0x3,%ebp
jne    1227 <mode_delegate+0xc7>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <sqlite_get_delegated_users@plt>
mov    0x18(%r14),%rdx
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sqlite_delegate_address@plt>
mov    0x18(%r14),%rdx
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sqlite_delegate_user@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"%\00"
@.str.1 = [8 x i8] c"address\00"
@.str.2 = [5 x i8] c"user\00"
define i32 @mode_delegate(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i32 0, i32* %7
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32*, i32** %4
%12 = call i32 @sqlite_get_delegated(i32* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
br label %85
13: ; preds = %3
%14 = load i8**, i8*** %6
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %45, label %19
19: ; preds = %13
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32*, i32** %4
%24 = call i32 @sqlite_get_delegated_addresses(i32* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %24, i32* %7
br label %44
25: ; preds = %19
%26 = load i32, i32* %5
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32*, i32** %4
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @sqlite_get_delegated_addresses(i32* %29, i8* %32)
store i32 %33, i32* %7
br label %43
34: ; preds = %25
%35 = load i32*, i32** %4
%36 = load i8**, i8*** %6
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 3
%41 = load i8*, i8** %40
%42 = call i32 @sqlite_delegate_address(i32* %35, i8* %38, i8* %41)
store i32 %42, i32* %7
br label %43
43: ; preds = %34, %28
br label %44
44: ; preds = %43, %22
br label %84
45: ; preds = %13
%46 = load i8**, i8*** %6
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @strcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%50 = icmp ne i32 %49, 0
br i1 %50, label %77, label %51
51: ; preds = %45
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 3
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32*, i32** %4
%56 = call i32 @sqlite_get_delegated_users(i32* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %56, i32* %7
br label %76
57: ; preds = %51
%58 = load i32, i32* %5
%59 = icmp slt i32 %58, 4
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load i32*, i32** %4
%62 = load i8**, i8*** %6
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = call i32 @sqlite_get_delegated_users(i32* %61, i8* %64)
store i32 %65, i32* %7
br label %75
66: ; preds = %57
%67 = load i32*, i32** %4
%68 = load i8**, i8*** %6
%69 = getelementptr inbounds i8*, i8** %68, i64 2
%70 = load i8*, i8** %69
%71 = load i8**, i8*** %6
%72 = getelementptr inbounds i8*, i8** %71, i64 3
%73 = load i8*, i8** %72
%74 = call i32 @sqlite_delegate_user(i32* %67, i8* %70, i8* %73)
store i32 %74, i32* %7
br label %75
75: ; preds = %66, %60
br label %76
76: ; preds = %75, %54
br label %83
77: ; preds = %45
%78 = load i32*, i32** %4
%79 = load i8**, i8*** %6
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @sqlite_get_delegated(i32* %78, i8* %81)
store i32 %82, i32* %7
br label %83
83: ; preds = %77, %76
br label %84
84: ; preds = %83, %44
br label %85
85: ; preds = %84, %10
%86 = load i32, i32* %7
ret i32 %86
}

LLVM IR (-O2):
@.str = [2 x i8] c"%\00"
@.str.1 = [8 x i8] c"address\00"
@.str.2 = [5 x i8] c"user\00"
define i32 @mode_delegate(i32* %0, i32 %1, i8** nocapture %2) {
%4 = icmp slt i32 %1, 2
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @sqlite_get_delegated(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %45
7: ; preds = %3
%8 = getelementptr inbounds i8*, i8** %2, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = icmp ult i32 %1, 3
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @sqlite_get_delegated_addresses(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %45
16: ; preds = %12
%17 = icmp eq i32 %1, 3
%18 = getelementptr inbounds i8*, i8** %2, i64 2
%19 = load i8*, i8** %18
br i1 %17, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @sqlite_get_delegated_addresses(i32* %0, i8* %19)
br label %45
22: ; preds = %16
%23 = getelementptr inbounds i8*, i8** %2, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @sqlite_delegate_address(i32* %0, i8* %19, i8* %24)
br label %45
26: ; preds = %7
%27 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = icmp ult i32 %1, 3
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = tail call i32 @sqlite_get_delegated_users(i32* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %45
33: ; preds = %29
%34 = icmp eq i32 %1, 3
%35 = getelementptr inbounds i8*, i8** %2, i64 2
%36 = load i8*, i8** %35
br i1 %34, label %37, label %39
37: ; preds = %33
%38 = tail call i32 @sqlite_get_delegated_users(i32* %0, i8* %36)
br label %45
39: ; preds = %33
%40 = getelementptr inbounds i8*, i8** %2, i64 3
%41 = load i8*, i8** %40
%42 = tail call i32 @sqlite_delegate_user(i32* %0, i8* %36, i8* %41)
br label %45
43: ; preds = %26
%44 = tail call i32 @sqlite_get_delegated(i32* %0, i8* %9)
br label %45
45: ; preds = %20, %22, %14, %31, %39, %37, %43, %5
%46 = phi i32 [ %6, %5 ], [ %44, %43 ], [ %32, %31 ], [ %38, %37 ], [ %42, %39 ], [ %15, %14 ], [ %21, %20 ], [ %25, %22 ]
ret i32 %46
}