#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 /*<<< orphan*/ logprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ router_valid(char *);
int sqlite_add_address(int /*<<< orphan*/ *, char *, char *, char *);
int sqlite_add_address_order(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                             char *, char *);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int mode_add(sqlite3 *db, int argc, char *argv[]) {
  int status = 0;
  if (argc < 3) {
    logprintf(0, "Missing arguments\n\n");
    return -1;
  }
  if (!router_valid(argv[2])) {
    logprintf(0, "Unknown router %s, adding anyway\n", argv[2]);
  }
  if (argc == 3) {
    status = sqlite_add_address(db, argv[1], argv[2], NULL);
  } else if (argc == 4) {
    status = sqlite_add_address(db, argv[1], argv[2], argv[3]);
  } else if (argc == 5) {
    status = sqlite_add_address_order(db, argv[1], strtol(argv[4], NULL, 10),
                                      argv[2], argv[3]);
  } else {
    logprintf(0, "Too many arguments\n\n");
    status = -1;
  }
  return status;
}


x86 assembly (clang, -O0):
<mode_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1190 <mode_add+0x40>
xor    %edi,%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1070 <logprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a2 <mode_add+0x152>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <router_valid@plt>
cmp    $0x0,%eax
jne    11be <mode_add+0x6e>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %edi,%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1070 <logprintf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    11ed <mode_add+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <sqlite_add_address@plt>
mov    %eax,-0x24(%rbp)
jmp    129c <mode_add+0x14c>
cmpl   $0x4,-0x14(%rbp)
jne    1220 <mode_add+0xd0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rcx
call   1060 <sqlite_add_address@plt>
mov    %eax,-0x24(%rbp)
jmp    1297 <mode_add+0x147>
cmpl   $0x5,-0x14(%rbp)
jne    127b <mode_add+0x12b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%r8
call   1030 <sqlite_add_address_order@plt>
mov    %eax,-0x24(%rbp)
jmp    1292 <mode_add+0x142>
xor    %edi,%edi
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1070 <logprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    1297 <mode_add+0x147>
jmp    129c <mode_add+0x14c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_add>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jg     1165 <mode_add+0x15>
lea    0xea0(%rip),%rsi
jmp    11fd <mode_add+0xad>
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x10(%rdx),%rdi
call   1050 <router_valid@plt>
test   %eax,%eax
je     1198 <mode_add+0x48>
cmp    $0x5,%ebp
je     11b1 <mode_add+0x61>
cmp    $0x4,%ebp
je     11de <mode_add+0x8e>
cmp    $0x3,%ebp
jne    11f6 <mode_add+0xa6>
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
mov    %r14,%rdi
xor    %ecx,%ecx
jmp    11ed <mode_add+0x9d>
mov    0x10(%rbx),%rdx
lea    0xe71(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <logprintf@plt>
cmp    $0x5,%ebp
jne    117f <mode_add+0x2f>
mov    0x8(%rbx),%rbp
mov    0x20(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x10(%rbx),%rcx
mov    0x18(%rbx),%r8
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <sqlite_add_address_order@plt>
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%rdx
mov    0x18(%rbx),%rcx
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <sqlite_add_address@plt>
lea    0xe39(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1070 <logprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Missing arguments\0A\0A\00"
@.str.1 = [34 x i8] c"Unknown router %s, adding anyway\0A\00"
@.str.2 = [21 x i8] c"Too many arguments\0A\0A\00"
define i32 @mode_add(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 0, i32* %8
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
13: ; preds = %3
%14 = load i8**, i8*** %7
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @router_valid(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = load i8**, i8*** %7
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %13
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32*, i32** %5
%29 = load i8**, i8*** %7
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %7
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @sqlite_add_address(i32* %28, i8* %31, i8* %34, i8* null)
store i32 %35, i32* %8
br label %74
36: ; preds = %24
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 4
br i1 %38, label %39, label %51
39: ; preds = %36
%40 = load i32*, i32** %5
%41 = load i8**, i8*** %7
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %7
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %7
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @sqlite_add_address(i32* %40, i8* %43, i8* %46, i8* %49)
store i32 %50, i32* %8
br label %73
51: ; preds = %36
%52 = load i32, i32* %6
%53 = icmp eq i32 %52, 5
br i1 %53, label %54, label %70
54: ; preds = %51
%55 = load i32*, i32** %5
%56 = load i8**, i8*** %7
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = load i8**, i8*** %7
%60 = getelementptr inbounds i8*, i8** %59, i64 4
%61 = load i8*, i8** %60
%62 = call i32 @strtol(i8* %61, i32* null, i32 10)
%63 = load i8**, i8*** %7
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %7
%67 = getelementptr inbounds i8*, i8** %66, i64 3
%68 = load i8*, i8** %67
%69 = call i32 @sqlite_add_address_order(i32* %55, i8* %58, i32 %62, i8* %65, i8* %68)
store i32 %69, i32* %8
br label %72
70: ; preds = %51
%71 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %8
br label %72
72: ; preds = %70, %54
br label %73
73: ; preds = %72, %39
br label %74
74: ; preds = %73, %27
%75 = load i32, i32* %8
store i32 %75, i32* %4
br label %76
76: ; preds = %74, %11
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@.str = [20 x i8] c"Missing arguments\0A\0A\00"
@.str.1 = [34 x i8] c"Unknown router %s, adding anyway\0A\00"
@.str.2 = [21 x i8] c"Too many arguments\0A\0A\00"
define i32 @mode_add(i32* %0, i32 %1, i8** nocapture %2) {
%4 = icmp slt i32 %1, 3
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %40
7: ; preds = %3
%8 = getelementptr inbounds i8*, i8** %2, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @router_valid(i8* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %8
%14 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %7
switch i32 %1, label %38 [
i32 3, label %16
i32 4, label %21
i32 5, label %28
]
16: ; preds = %15
%17 = getelementptr inbounds i8*, i8** %2, i64 1
%18 = load i8*, i8** %17
%19 = load i8*, i8** %8
%20 = tail call i32 @sqlite_add_address(i32* %0, i8* %18, i8* %19, i8* null)
br label %40
21: ; preds = %15
%22 = getelementptr inbounds i8*, i8** %2, i64 1
%23 = load i8*, i8** %22
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8*, i8** %2, i64 3
%26 = load i8*, i8** %25
%27 = tail call i32 @sqlite_add_address(i32* %0, i8* %23, i8* %24, i8* %26)
br label %40
28: ; preds = %15
%29 = getelementptr inbounds i8*, i8** %2, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8*, i8** %2, i64 4
%32 = load i8*, i8** %31
%33 = tail call i32 @strtol(i8* nocapture %32, i32* null, i32 10)
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8*, i8** %2, i64 3
%36 = load i8*, i8** %35
%37 = tail call i32 @sqlite_add_address_order(i32* %0, i8* %30, i32 %33, i8* %34, i8* %36)
br label %40
38: ; preds = %15
%39 = tail call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %16, %28, %38, %21, %5
%41 = phi i32 [ -1, %5 ], [ %20, %16 ], [ %27, %21 ], [ %37, %28 ], [ -1, %38 ]
ret i32 %41
}