#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 *, ...);
int /*<<< orphan*/ sqlite3_free(char *);
char *sqlite3_mprintf(char *, char *, char *, char *);
char *strchr(char *, char);
char *strdup(char *);
void faq(const char *file) {
  FILE *fp = fopen(file, "r");
  if (!fp)
    return;
  printf("create table if not exists FAQ (NAME, AUTHOR, CONTENT);\n");
  printf("INSERT INTO REQUESTS (NAME, COUNT) VALUES ('FAQ', 0);\n");
  size_t size = 0;
  char *line = 0;
  while (getline(&line, &size, fp) != EOF) {
    char *name = strdup(line);
    char *author = strdup(strchr(name, ' ') + 1);
    char *content = strchr(author, ' ') + 1;
    *strchr(name, ' ') = '\0';
    *strchr(author, ' ') = '\0';
    char *nl = strchr(content, '\r');
    if (!nl)
      nl = strchr(content, '\n');
    if (nl)
      *nl = '\0';
    char *esc = sqlite3_mprintf(
        "INSERT INTO FAQ (NAME, AUTHOR, CONTENT) VALUES ('%q', '%q', '%q');",
        name, author, content);
    printf("%s\n", esc);
    sqlite3_free(esc);
    free(name);
    free(author);
  }
  free(line);
  fclose(fp);
}


x86 assembly (clang, -O0):
<faq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c0 <faq+0x30>
jmp    1311 <faq+0x181>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%rax
je     12ff <faq+0x16f>
mov    -0x20(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%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    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
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    129f <faq+0x10f>
mov    -0x38(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12b1 <faq+0x121>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xdae(%rip),%rdi
call   10a0 <sqlite3_mprintf@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1090 <sqlite3_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11ec <faq+0x5c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<faq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe5b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12f4 <faq+0x164>
mov    %rax,%r13
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb4(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   1080 <getline@plt>
mov    0x2def(%rip),%r12
jmp    124d <faq+0xbd>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
lea    0xdf8(%rip),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   10a0 <sqlite3_mprintf@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1090 <sqlite3_free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   1080 <getline@plt>
cmp    (%r12),%rax
je     12e2 <faq+0x152>
mov    0x8(%rsp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,%r14
add    $0x1,%r14
mov    %r15,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    1200 <faq+0x70>
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
jne    1200 <faq+0x70>
jmp    1203 <faq+0x73>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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