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

/* Variables and functions */
char *find_query(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int ssds_cgi_new_item(int, char *, char *, char *);
int do_add_item(int dbfd, int ctxidx, int qnum) {
  int ret;
  char *namesp;
  char *idsp;
  char *classsp;
  ret = 0;
  classsp = find_query("class_name", qnum);
  namesp = find_query("new_item_name", qnum);
  idsp = find_query("new_item_id", qnum);
  if (classsp && namesp) {
    ret = ssds_cgi_new_item(dbfd, classsp, namesp, idsp);
    printf("<br>Created new item (%s) in class (%s)  \n", namesp, classsp);
  } else {
    printf("<br>New Item Name not defined\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<do_add_item>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeae(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea6(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea1(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c9 <do_add_item+0x99>
cmpq   $0x0,-0x18(%rbp)
je     11c9 <do_add_item+0x99>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <ssds_cgi_new_item@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <do_add_item+0xa7>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_add_item>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %edi,%r14d
lea    0xead(%rip),%rdi
mov    %edx,%esi
call   1060 <find_query@plt>
mov    %rax,%r15
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
call   1060 <find_query@plt>
mov    %rax,%rbp
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
call   1060 <find_query@plt>
test   %r15,%r15
je     11b1 <do_add_item+0x71>
test   %rbp,%rbp
je     11b1 <do_add_item+0x71>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1050 <ssds_cgi_new_item@plt>
mov    %eax,%ebx
lea    0xe85(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
jmp    11bf <do_add_item+0x7f>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"class_name\00"
@.str.1 = [14 x i8] c"new_item_name\00"
@.str.2 = [12 x i8] c"new_item_id\00"
@.str.3 = [43 x i8] c"<br>Created new item (%s) in class (%s) \0A\00"
@.str.4 = [31 x i8] c"<br>New Item Name not defined\0A\00"
define i32 @do_add_item(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %6
%12 = call i8* @find_query(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
store i8* %12, i8** %10
%13 = load i32, i32* %6
%14 = call i8* @find_query(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i8* %14, i8** %8
%15 = load i32, i32* %6
%16 = call i8* @find_query(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %15)
store i8* %16, i8** %9
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %31
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %4
%24 = load i8*, i8** %10
%25 = load i8*, i8** %8
%26 = load i8*, i8** %9
%27 = call i32 @ssds_cgi_new_item(i32 %23, i8* %24, i8* %25, i8* %26)
store i32 %27, i32* %7
%28 = load i8*, i8** %8
%29 = load i8*, i8** %10
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %28, i8* %29)
br label %33
31: ; preds = %19, %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
@.str = [11 x i8] c"class_name\00"
@.str.1 = [14 x i8] c"new_item_name\00"
@.str.2 = [12 x i8] c"new_item_id\00"
@.str.3 = [43 x i8] c"<br>Created new item (%s) in class (%s) \0A\00"
@str = [30 x i8] c"<br>New Item Name not defined\00"
define i32 @do_add_item(i32 %0, i32 %1, i32 %2) {
%4 = tail call i8* @find_query(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %2)
%5 = tail call i8* @find_query(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%6 = tail call i8* @find_query(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%7 = icmp ne i8* %4, null
%8 = icmp ne i8* %5, null
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @ssds_cgi_new_item(i32 %0, i8* %4, i8* %5, i8* %6)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %4)
br label %15
13: ; preds = %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ %11, %10 ], [ 0, %13 ]
ret i32 %16
}