#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 */
struct sockaddr_storage {
  int dummy;
};
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
scalar_t__ SQLITE_OK;
char *allocateString(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *ipToString(struct sockaddr_storage const *);
scalar_t__ sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int /*<<< orphan*/ stderr;
void insertAddress(sqlite3 *database, const struct sockaddr_storage *address) {
  char *address_string = ipToString(address);
  char *query = allocateString(
      "INSERT INTO connections (address, time) VALUES (\"%s\", datetime());",
      address_string);
  char *error;
  if (sqlite3_exec(database, query, NULL, NULL, &error) != SQLITE_OK) {
    fprintf(stderr, "Failed to insert row: %s.\n", error);
    sqlite3_free(error);
  }
  free(address_string);
  free(query);
}


x86 assembly (clang, -O0):
<insertAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <ipToString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1030 <allocateString@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rdx
call   1050 <sqlite3_exec@plt>
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
je     11db <insertAddress+0x7b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <sqlite3_free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertAddress>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <ipToString@plt>
mov    %rax,%r14
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
call   1030 <allocateString@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%r8
mov    %r15,%rdi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <sqlite3_exec@plt>
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <insertAddress+0x6d>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe85(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
@.str = [67 x i8] c"INSERT INTO connections (address, time) VALUES (\22%s\22, datetime());\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Failed to insert row: %s.\0A\00"
define void @insertAddress(i32* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i32*
%4 = alloca %struct.sockaddr_storage*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32* %0, i32** %3
store %struct.sockaddr_storage* %1, %struct.sockaddr_storage** %4
%8 = load %struct.sockaddr_storage*, %struct.sockaddr_storage** %4
%9 = call i8* @ipToString(%struct.sockaddr_storage* %8)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = call i8* @allocateString(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %10)
store i8* %11, i8** %6
%12 = load i32*, i32** %3
%13 = load i8*, i8** %6
%14 = call i64 @sqlite3_exec(i32* %12, i8* %13, i32* null, i32* null, i8** %7)
%15 = load i64, i64* @SQLITE_OK
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %7
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %7
%22 = call i32 @sqlite3_free(i8* %21)
br label %23
23: ; preds = %17, %2
%24 = load i8*, i8** %5
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
@.str = [67 x i8] c"INSERT INTO connections (address, time) VALUES (\22%s\22, datetime());\00"
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Failed to insert row: %s.\0A\00"
define void @insertAddress(i32* %0, %struct.sockaddr_storage* %1) {
%3 = alloca i8*
%4 = tail call i8* @ipToString(%struct.sockaddr_storage* %1)
%5 = tail call i8* @allocateString(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = bitcast i8** %3 to i8*
%7 = call i64 @sqlite3_exec(i32* %0, i8* %5, i32* null, i32* null, i8** %3)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
%15 = call i32 @sqlite3_free(i8* %14)
br label %16
16: ; preds = %10, %2
%17 = call i32 @free(i8* %4)
%18 = call i32 @free(i8* %5)
ret void
}