#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 */
scalar_t__ db_class_id_fetch(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ db_class_insert(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *db_db();
int /*<<< orphan*/ fatal4(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int class_id_furnish(char *c) {
  int x;
  sqlite3 *db = db_db();
  x = 0;
  if (db_class_id_fetch(db, c, &x))
    return x;
  db_class_insert(db, c);
  if (!db_class_id_fetch(db, c, &x))
    fatal4("failed to insert class `", c, "': ", sqlite3_errmsg(db));
  return x;
}


x86 assembly (clang, -O0):
<class_id_furnish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <db_db@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <db_class_id_fetch@plt>
cmp    $0x0,%rax
je     1194 <class_id_furnish+0x44>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <class_id_furnish+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <db_class_insert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <db_class_id_fetch@plt>
cmp    $0x0,%rax
jne    11e6 <class_id_furnish+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%ecx
lea    0xe26(%rip),%rdi
lea    0xe38(%rip),%rdx
call   1030 <fatal4@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<class_id_furnish>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <db_db@plt>
mov    %rax,%rbx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <db_class_id_fetch@plt>
test   %rax,%rax
jne    11be <class_id_furnish+0x6e>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <db_class_insert@plt>
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <db_class_id_fetch@plt>
test   %rax,%rax
jne    11be <class_id_furnish+0x6e>
mov    %rbx,%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe53(%rip),%rdi
lea    0xe65(%rip),%rdx
mov    %r14,%rsi
mov    %eax,%ecx
call   1030 <fatal4@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"failed to insert class `\00"
@.str.1 = [4 x i8] c"': \00"
define i32 @class_id_furnish(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %3
%6 = call i32* (...) @db_db()
store i32* %6, i32** %5
store i32 0, i32* %4
%7 = load i32*, i32** %5
%8 = load i8*, i8** %3
%9 = call i64 @db_class_id_fetch(i32* %7, i8* %8, i32* %4)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %28
13: ; preds = %1
%14 = load i32*, i32** %5
%15 = load i8*, i8** %3
%16 = call i32 @db_class_insert(i32* %14, i8* %15)
%17 = load i32*, i32** %5
%18 = load i8*, i8** %3
%19 = call i64 @db_class_id_fetch(i32* %17, i8* %18, i32* %4)
%20 = icmp ne i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i32*, i32** %5
%24 = call i32 @sqlite3_errmsg(i32* %23)
%25 = call i32 @fatal4(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %13
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %11
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [25 x i8] c"failed to insert class `\00"
@.str.1 = [4 x i8] c"': \00"
define i32 @class_id_furnish(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* (...) @db_db()
store i32 0, i32* %2
%5 = call i64 @db_class_id_fetch(i32* %4, i8* %0, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = call i32 @db_class_insert(i32* %4, i8* %0)
%9 = call i64 @db_class_id_fetch(i32* %4, i8* %0, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 @sqlite3_errmsg(i32* %4)
%13 = call i32 @fatal4(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7, %11, %1
%15 = load i32, i32* %2
ret i32 %15
}