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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_mprintf(char *, char const *, char *, char *);
char *strchr(char *, char);
char *strdup(char *);
void table(const char *file, const char *table) {
  FILE *fp = fopen(file, "r");
  if (!fp)
    return;
  printf("create table if not exists %s (NAME, CONTENT);\n", table);
  printf("INSERT INTO REQUESTS (NAME, COUNT) VALUES ('%s', 0);\n", table);
  size_t size = 0;
  char *line = 0;
  while (getline(&line, &size, fp) != EOF) {
    char *name = strdup(line);
    char *content = strchr(name, ' ') + 1;
    *strchr(name, ' ') = '\0';
    char *nl = strchr(content, '\r');
    if (!nl)
      nl = strchr(content, '\n');
    if (nl)
      *nl = '\0';
    char *esc =
        sqlite3_mprintf("INSERT INTO %s (NAME, CONTENT) VALUES ('%q', '%q');",
                        table, name, content);
    printf("%s\n", esc);
    sqlite3_free(esc);
    free(name);
  }
  free(line);
  fclose(fp);
}


x86 assembly (clang, -O0):
<table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <table+0x34>
jmp    12df <table+0x14f>
mov    -0x10(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     12cd <table+0x13d>
mov    -0x28(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1278 <table+0xe8>
mov    -0x38(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     128a <table+0xfa>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xdcb(%rip),%rdi
call   10a0 <sqlite3_mprintf@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1090 <sqlite3_free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11f4 <table+0x64>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
lea    0xe58(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1215 <table+0x85>
mov    %rax,%rbx
lea    0xe46(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
lea    0xe67(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
jne    1224 <table+0x94>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r13
jmp    128a <table+0xfa>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
lea    0xe2e(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   10a0 <sqlite3_mprintf@plt>
mov    %rax,%rbp
lea    0xe4a(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1090 <sqlite3_free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%rax
je     1203 <table+0x73>
mov    0x8(%rsp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
add    $0x1,%r12
mov    %r12,%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1230 <table+0xa0>
mov    %r12,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1230 <table+0xa0>
jmp    1233 <table+0xa3>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [48 x i8] c"create table if not exists %s (NAME, CONTENT);\0A\00"
@.str.2 = [54 x i8] c"INSERT INTO REQUESTS (NAME, COUNT) VALUES ('%s', 0);\0A\00"
@EOF = global i64 0
@.str.3 = [52 x i8] c"INSERT INTO %s (NAME, CONTENT) VALUES ('%q', '%q');\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @table(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %2
br label %63
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i64 0, i64* %6
store i8* null, i8** %7
br label %22
22: ; preds = %47, %17
%23 = load i32*, i32** %5
%24 = call i64 @getline(i8** %7, i64* %6, i32* %23)
%25 = load i64, i64* @EOF
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %58
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = call i8* @strdup(i8* %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = call i8* @strchr(i8* %30, i8 signext 32)
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %9
%33 = load i8*, i8** %8
%34 = call i8* @strchr(i8* %33, i8 signext 32)
store i8 0, i8* %34
%35 = load i8*, i8** %9
%36 = call i8* @strchr(i8* %35, i8 signext 13)
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %42, label %39
39: ; preds = %27
%40 = load i8*, i8** %9
%41 = call i8* @strchr(i8* %40, i8 signext 10)
store i8* %41, i8** %10
br label %42
42: ; preds = %39, %27
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = load i8*, i8** %10
store i8 0, i8* %46
br label %47
47: ; preds = %45, %42
%48 = load i8*, i8** %4
%49 = load i8*, i8** %8
%50 = load i8*, i8** %9
%51 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %49, i8* %50)
store i8* %51, i8** %11
%52 = load i8*, i8** %11
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %11
%55 = call i32 @sqlite3_free(i8* %54)
%56 = load i8*, i8** %8
%57 = call i32 @free(i8* %56)
br label %22
58: ; preds = %22
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
%61 = load i32*, i32** %5
%62 = call i32 @fclose(i32* %61)
br label %63
63: ; preds = %58, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [48 x i8] c"create table if not exists %s (NAME, CONTENT);\0A\00"
@.str.2 = [54 x i8] c"INSERT INTO REQUESTS (NAME, COUNT) VALUES ('%s', 0);\0A\00"
@EOF = global i64 0
@.str.3 = [52 x i8] c"INSERT INTO %s (NAME, CONTENT) VALUES ('%q', '%q');\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @table(i8* nocapture %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %39, label %7
7: ; preds = %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%10 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%11 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%12 = call i64 @getline(i8** %4, i64* %3, i32* %5)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %35, label %15
15: ; preds = %7, %27
%16 = load i8*, i8** %4
%17 = call i8* @strdup(i8* %16)
%18 = call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 32)
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %18
%20 = call i8* @strchr(i8* %19, i8 signext 13)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i8* @strchr(i8* %19, i8 signext 10)
%24 = icmp eq i8* %23, null
br i1 %24, label %27, label %25
25: ; preds = %15, %22
%26 = phi i8* [ %23, %22 ], [ %20, %15 ]
store i8 0, i8* %26
br label %27
27: ; preds = %25, %22
%28 = call i8* @sqlite3_mprintf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %17, i8* %19)
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = call i32 @sqlite3_free(i8* %28)
%31 = call i32 @free(i8* %17)
%32 = call i64 @getline(i8** %4, i64* %3, i32* %5)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %15
35: ; preds = %27, %7
%36 = load i8*, i8** %4
%37 = call i32 @free(i8* %36)
%38 = call i32 @fclose(i32* %5)
br label %39
39: ; preds = %2, %35
ret void
}