#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_update_address(int /*<<< orphan*/ *, int /*<<< orphan*/, char *,
                          char *);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int mode_update(sqlite3 *db, int argc, char *argv[]) {
  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) {
    return sqlite_update_address(db, strtol(argv[1], NULL, 10), argv[2], NULL);
  } else {
    return sqlite_update_address(db, strtol(argv[1], NULL, 10), argv[2],
                                 argv[3]);
  }
}


x86 assembly (clang, -O0):
<mode_update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    1179 <mode_update+0x39>
xor    %edi,%edi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1060 <logprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <mode_update+0xea>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <router_valid@plt>
cmp    $0x0,%eax
jne    11a7 <mode_update+0x67>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %edi,%edi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1060 <logprintf@plt>
cmpl   $0x3,-0x14(%rbp)
jne    11ee <mode_update+0xae>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <sqlite_update_address@plt>
mov    %eax,-0x4(%rbp)
jmp    122a <mode_update+0xea>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%rcx
call   1050 <sqlite_update_address@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_update>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jg     1163 <mode_update+0x23>
lea    0xeb0(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <logprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x10(%rdx),%rdi
call   1040 <router_valid@plt>
test   %eax,%eax
jne    118c <mode_update+0x4c>
mov    0x10(%rbx),%rdx
lea    0xe91(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <logprintf@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x10(%rbx),%rdx
cmp    $0x3,%ebp
jne    11ae <mode_update+0x6e>
mov    %r14,%rdi
mov    %eax,%esi
xor    %ecx,%ecx
jmp    11b7 <mode_update+0x77>
mov    0x18(%rbx),%rcx
mov    %r14,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <sqlite_update_address@plt>

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"
define i32 @mode_update(i32* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8**
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = 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 %49
12: ; preds = %3
%13 = load i8**, i8*** %7
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @router_valid(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = load i8**, i8*** %7
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %18, %12
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32*, i32** %5
%28 = load i8**, i8*** %7
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strtol(i8* %30, i32* null, i32 10)
%32 = load i8**, i8*** %7
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @sqlite_update_address(i32* %27, i32 %31, i8* %34, i8* null)
store i32 %35, i32* %4
br label %49
36: ; preds = %23
%37 = load i32*, i32** %5
%38 = load i8**, i8*** %7
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strtol(i8* %40, i32* null, i32 10)
%42 = load i8**, i8*** %7
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %7
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = call i32 @sqlite_update_address(i32* %37, i32 %41, i8* %44, i8* %47)
store i32 %48, i32* %4
br label %49
49: ; preds = %36, %26, %10
%50 = load i32, i32* %4
ret i32 %50
}

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"
define i32 @mode_update(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 %27
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
%16 = icmp eq i32 %1, 3
%17 = getelementptr inbounds i8*, i8** %2, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strtol(i8* nocapture %18, i32* null, i32 10)
%20 = load i8*, i8** %8
br i1 %16, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @sqlite_update_address(i32* %0, i32 %19, i8* %20, i8* null)
br label %27
23: ; preds = %15
%24 = getelementptr inbounds i8*, i8** %2, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32 @sqlite_update_address(i32* %0, i32 %19, i8* %20, i8* %25)
br label %27
27: ; preds = %23, %21, %5
%28 = phi i32 [ -1, %5 ], [ %22, %21 ], [ %26, %23 ]
ret i32 %28
}