#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_field(int, char *, char *, char *, char *, char *, char *);
int do_add_field(int dbfd, int ctxidx, int qnum) {
  int ret;
  char *namesp;
  char *typesp;
  char *valsp;
  char *idsp;
  char *lensp;
  char *classsp;
  ret = 0;
  classsp = find_query("class_name", qnum);
  namesp = find_query("new_field_name", qnum);
  typesp = find_query("new_field_type", qnum);
  valsp = find_query("new_field_value", qnum);
  idsp = find_query("new_field_id", qnum);
  lensp = find_query("new_field_len", qnum);
  if (classsp && namesp) {
    ret = ssds_cgi_new_field(dbfd, classsp, namesp, typesp, valsp, idsp, lensp);
    printf("<br>Created new field (%s) in class (%s)  \n", namesp, classsp);
  } else {
    printf("<br>New field Name not defined\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<do_add_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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,-0x40(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea6(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea2(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1050 <find_query@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1212 <do_add_field+0xe2>
cmpq   $0x0,-0x18(%rbp)
je     1212 <do_add_field+0xe2>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
mov    %rax,(%rsp)
call   1040 <ssds_cgi_new_field@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1220 <do_add_field+0xf0>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_add_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %edi,0x14(%rsp)
lea    0xea5(%rip),%rdi
mov    %edx,%esi
call   1060 <find_query@plt>
mov    %rax,%rbx
lea    0xe9f(%rip),%rdi
mov    %ebp,%esi
call   1060 <find_query@plt>
mov    %rax,%r14
lea    0xe9d(%rip),%rdi
mov    %ebp,%esi
call   1060 <find_query@plt>
mov    %rax,%r12
lea    0xe9b(%rip),%rdi
mov    %ebp,%esi
call   1060 <find_query@plt>
mov    %rax,%r13
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
call   1060 <find_query@plt>
mov    %rax,%r15
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
call   1060 <find_query@plt>
test   %rbx,%rbx
je     11f7 <do_add_field+0xb7>
test   %r14,%r14
je     11f7 <do_add_field+0xb7>
mov    %rax,(%rsp)
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %r15,%r9
call   1050 <ssds_cgi_new_field@plt>
mov    %eax,%ebp
lea    0xe6e(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
jmp    1205 <do_add_field+0xc5>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"class_name\00"
@.str.1 = [15 x i8] c"new_field_name\00"
@.str.2 = [15 x i8] c"new_field_type\00"
@.str.3 = [16 x i8] c"new_field_value\00"
@.str.4 = [13 x i8] c"new_field_id\00"
@.str.5 = [14 x i8] c"new_field_len\00"
@.str.6 = [44 x i8] c"<br>Created new field (%s) in class (%s) \0A\00"
@.str.7 = [32 x i8] c"<br>New field Name not defined\0A\00"
define i32 @do_add_field(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*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%14 = load i32, i32* %6
%15 = call i8* @find_query(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %14)
store i8* %15, i8** %13
%16 = load i32, i32* %6
%17 = call i8* @find_query(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i8* %17, i8** %8
%18 = load i32, i32* %6
%19 = call i8* @find_query(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i8* %19, i8** %9
%20 = load i32, i32* %6
%21 = call i8* @find_query(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %20)
store i8* %21, i8** %10
%22 = load i32, i32* %6
%23 = call i8* @find_query(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %22)
store i8* %23, i8** %11
%24 = load i32, i32* %6
%25 = call i8* @find_query(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %24)
store i8* %25, i8** %12
%26 = load i8*, i8** %13
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %43
28: ; preds = %3
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32, i32* %4
%33 = load i8*, i8** %13
%34 = load i8*, i8** %8
%35 = load i8*, i8** %9
%36 = load i8*, i8** %10
%37 = load i8*, i8** %11
%38 = load i8*, i8** %12
%39 = call i32 @ssds_cgi_new_field(i32 %32, i8* %33, i8* %34, i8* %35, i8* %36, i8* %37, i8* %38)
store i32 %39, i32* %7
%40 = load i8*, i8** %8
%41 = load i8*, i8** %13
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %40, i8* %41)
br label %45
43: ; preds = %28, %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %31
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
@.str = [11 x i8] c"class_name\00"
@.str.1 = [15 x i8] c"new_field_name\00"
@.str.2 = [15 x i8] c"new_field_type\00"
@.str.3 = [16 x i8] c"new_field_value\00"
@.str.4 = [13 x i8] c"new_field_id\00"
@.str.5 = [14 x i8] c"new_field_len\00"
@.str.6 = [44 x i8] c"<br>Created new field (%s) in class (%s) \0A\00"
@str = [31 x i8] c"<br>New field Name not defined\00"
define i32 @do_add_field(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 ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%6 = tail call i8* @find_query(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%7 = tail call i8* @find_query(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%8 = tail call i8* @find_query(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %2)
%9 = tail call i8* @find_query(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %2)
%10 = icmp ne i8* %4, null
%11 = icmp ne i8* %5, null
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = tail call i32 @ssds_cgi_new_field(i32 %0, i8* %4, i8* %5, i8* %6, i8* %7, i8* %8, i8* %9)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %5, i8* %4)
br label %18
16: ; preds = %3
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = phi i32 [ %14, %13 ], [ 0, %16 ]
ret i32 %19
}