#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;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int SQLITE_OK;
int /*<<< orphan*/ add_quote(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/, char *, char *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ stderr;
int strlen(char *);
void load_words(sqlite3 *db, FILE *fp) {
  char *p;
  char *pword, *pexplain;
  int ret = 0;
  int id = 0;
  char buf[1024];
  char sql[1024];
  char *errmsg;
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    buf[strlen(buf) - 2] = '\0';
    add_quote(buf);
    pword = buf;
    p = buf;
    while (*p != ' ') {
      p++;
    }
    *p = '\0';
    p += 1;
    while (*p == ' ') {
      p++;
    }
    pexplain = p;
    sprintf(sql, "insert into words values(%d, '%s', '%s')", id++, pword,
            pexplain);
    ret = sqlite3_exec(db, sql, NULL, NULL, &errmsg);
    if (ret != SQLITE_OK) {
      fprintf(stderr, "Fail to sqlite3_exec : %s\n", errmsg);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<load_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12b7 <load_words+0x157>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x2,%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rdi
call   1070 <add_quote@plt>
lea    -0x430(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11fc <load_words+0x9c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11db <load_words+0x7b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1230 <load_words+0xd0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    120f <load_words+0xaf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xda7(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x830(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x838(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%eax
je     12b2 <load_words+0x152>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
mov    -0x838(%rbp),%rdx
lea    0xd81(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12b7 <load_words+0x157>
jmp    1181 <load_words+0x21>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_words>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %r12d,%r12d
lea    0x10(%rsp),%rbx
lea    0x410(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1245 <load_words+0xe5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <add_quote@plt>
lea    0xf(%rsp),%r8
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x20,0x1(%r8)
lea    0x1(%r8),%r8
jne    11d0 <load_words+0x70>
movb   $0x0,(%r8)
nop
cmpb   $0x20,0x1(%r8)
lea    0x1(%r8),%r8
je     11e0 <load_words+0x80>
lea    0x1(%r12),%ebp
mov    %r13,%rdi
lea    0xe06(%rip),%rsi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
call   1030 <sqlite3_exec@plt>
mov    %ebp,%r12d
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%eax
je     1190 <load_words+0x30>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"insert into words values(%d, '%s', '%s')\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Fail to sqlite3_exec : %s\0A\00"
define void @load_words(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i8*
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 0, i32* %8
store i32 0, i32* %9
br label %13
13: ; preds = %66, %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %14, i32 1024, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %67
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%25 = call i32 @add_quote(i8* %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
store i8* %26, i8** %6
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
store i8* %27, i8** %5
br label %28
28: ; preds = %33, %18
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 32
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %28
36: ; preds = %28
%37 = load i8*, i8** %5
store i8 0, i8* %37
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %5
br label %40
40: ; preds = %45, %36
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 32
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %5
br label %40
48: ; preds = %40
%49 = load i8*, i8** %5
store i8* %49, i8** %7
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
%53 = load i8*, i8** %6
%54 = load i8*, i8** %7
%55 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %51, i8* %53, i8* %54)
%56 = load i32*, i32** %3
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%58 = call i32 @sqlite3_exec(i32* %56, i8* %57, i32* null, i32* null, i8** %12)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = load i32, i32* @SQLITE_OK
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %66
62: ; preds = %48
%63 = load i32, i32* @stderr
%64 = load i8*, i8** %12
%65 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %64)
br label %67
66: ; preds = %48
br label %13
67: ; preds = %62, %13
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"insert into words values(%d, '%s', '%s')\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Fail to sqlite3_exec : %s\0A\00"
define void @load_words(i32* %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast i8** %5 to i8*
br label %9
9: ; preds = %30, %2
%10 = phi i32 [ 0, %2 ], [ %31, %30 ]
%11 = call i32* @fgets(i8* %6, i32 1024, i32* %1)
%12 = icmp eq i32* %11, null
br i1 %12, label %40, label %13
13: ; preds = %9
%14 = call i32 @strlen(i8* %6)
%15 = add nsw i32 %14, -2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @add_quote(i8* %6)
br label %19
19: ; preds = %19, %13
%20 = phi i8* [ %6, %13 ], [ %23, %19 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 32
%23 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %22, label %24, label %19
24: ; preds = %19
store i8 0, i8* %20
br label %25
25: ; preds = %25, %24
%26 = phi i8* [ %20, %24 ], [ %27, %25 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 32
br i1 %29, label %25, label %30
30: ; preds = %25
%31 = add nuw nsw i32 %10, 1
%32 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %6, i8* %27)
%33 = call i32 @sqlite3_exec(i32* %0, i8* %7, i32* null, i32* null, i8** %5)
%34 = load i32, i32* @SQLITE_OK
%35 = icmp eq i32 %33, %34
br i1 %35, label %9, label %36
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %5
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %9, %36
ret void
}