#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 char **MYSQL_ROW;
typedef int /*<<< orphan*/ MYSQL_RES;
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ deleteImageWithID(char *);
char **mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int mysql_num_rows(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_store_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
int cleanupPickedUp(MYSQL *sql_connection) {
  int num_rows, i;
  MYSQL_ROW row;
  MYSQL_RES *result;
  char queryString[300];
  char *fetchPickedUp = "SELECT orderID FROM orderTable WHERE expired='false' "
                        "AND pickedUp='true'";
  char *baseUpdatePickedUp =
      "UPDATE orderTable SET expired='true' WHERE orderID='";
  if (mysql_query(sql_connection, fetchPickedUp)) {
    syslog(LOG_INFO, "Unable to query SQL to find pickedUp orders");
    return 1;
  }
  result = mysql_store_result(sql_connection);
  if (result == NULL) {
    syslog(LOG_INFO, "Unable to get pickedUp results.");
    return 1;
  }
  num_rows = mysql_num_rows(result);
  if (num_rows < 0) {
    syslog(LOG_INFO, "ERROR: Problem retrieving num_rows");
    return 1;
  }
  if (num_rows < 1) {
    return 1;
  }
  strcpy(queryString, baseUpdatePickedUp);
  while (row = mysql_fetch_row(result)) {
    num_rows--;
    deleteImageWithID(row[0]);
    strcat(queryString, row[0]);
    if (num_rows < 1) {
      strcat(queryString, "'");
    } else {
      strcat(queryString, "' OR orderID='");
    }
  }
  if (mysql_query(sql_connection, queryString)) {
    syslog(LOG_INFO, "ERROR: Unable to update pickedup orders");
    syslog(LOG_INFO, "query: %s", queryString);
  } else {
  }
  mysql_free_result(result);
  return 0;
}


x86 assembly (clang, -O0):
<cleanupPickedUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x168(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x170(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x168(%rbp),%rsi
call   1040 <mysql_query@plt>
cmp    $0x0,%rax
je     11f8 <cleanupPickedUp+0x68>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1377 <cleanupPickedUp+0x1e7>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_store_result@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1233 <cleanupPickedUp+0xa3>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1377 <cleanupPickedUp+0x1e7>
mov    -0x28(%rbp),%rdi
call   1090 <mysql_num_rows@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    126c <cleanupPickedUp+0xdc>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
movl   $0x1,-0x4(%rbp)
jmp    1377 <cleanupPickedUp+0x1e7>
cmpl   $0x1,-0x14(%rbp)
jge    1282 <cleanupPickedUp+0xf2>
movl   $0x1,-0x4(%rbp)
jmp    1377 <cleanupPickedUp+0x1e7>
lea    -0x160(%rbp),%rdi
mov    -0x170(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <mysql_fetch_row@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     130e <cleanupPickedUp+0x17e>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <deleteImageWithID@plt>
lea    -0x160(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1080 <strcat@plt>
cmpl   $0x1,-0x14(%rbp)
jge    12f6 <cleanupPickedUp+0x166>
lea    -0x160(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1080 <strcat@plt>
jmp    1309 <cleanupPickedUp+0x179>
lea    -0x160(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1080 <strcat@plt>
jmp    1295 <cleanupPickedUp+0x105>
mov    -0x10(%rbp),%rdi
lea    -0x160(%rbp),%rsi
call   1040 <mysql_query@plt>
cmp    $0x0,%rax
je     1362 <cleanupPickedUp+0x1d2>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    -0x160(%rbp),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
jmp    1367 <cleanupPickedUp+0x1d7>
jmp    1367 <cleanupPickedUp+0x1d7>
mov    -0x28(%rbp),%rdi
call   1070 <mysql_free_result@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cleanupPickedUp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdi,%r14
lea    0xe55(%rip),%rsi
call   1040 <mysql_query@plt>
test   %rax,%rax
je     11e3 <cleanupPickedUp+0x53>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xeb9(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    $0x1,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   10b0 <mysql_store_result@plt>
test   %rax,%rax
je     12c1 <cleanupPickedUp+0x131>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <mysql_num_rows@plt>
test   %eax,%eax
js     12d6 <cleanupPickedUp+0x146>
je     11cc <cleanupPickedUp+0x3c>
mov    %eax,%r13d
lea    0xe36(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <mysql_fetch_row@plt>
test   %rax,%rax
je     1278 <cleanupPickedUp+0xe8>
mov    %rax,%rbx
mov    %rsp,%r12
xchg   %ax,%ax
lea    -0x1(%r13),%ebp
mov    (%rbx),%rdi
call   10a0 <deleteImageWithID@plt>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1080 <strcat@plt>
cmp    $0x2,%r13d
lea    0xe9b(%rip),%rsi
lea    0xe23(%rip),%rax
cmovl  %rax,%rsi
mov    %r12,%rdi
call   1080 <strcat@plt>
mov    %r15,%rdi
call   1050 <mysql_fetch_row@plt>
mov    %rax,%rbx
mov    %ebp,%r13d
test   %rax,%rax
jne    1230 <cleanupPickedUp+0xa0>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <mysql_query@plt>
test   %rax,%rax
je     12b2 <cleanupPickedUp+0x122>
mov    0x2d51(%rip),%rbx
mov    (%rbx),%edi
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1060 <syslog@plt>
mov    (%rbx),%edi
lea    0xe7c(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <syslog@plt>
mov    %r15,%rdi
call   1070 <mysql_free_result@plt>
xor    %eax,%eax
jmp    11d1 <cleanupPickedUp+0x41>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
jmp    11c5 <cleanupPickedUp+0x35>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
jmp    11c5 <cleanupPickedUp+0x35>

LLVM IR (-O0):
@.str = [73 x i8] c"SELECT orderID FROM orderTable WHERE expired='false' AND pickedUp='true'\00"
@.str.1 = [53 x i8] c"UPDATE orderTable SET expired='true' WHERE orderID='\00"
@LOG_INFO = global i32 0
@.str.2 = [44 x i8] c"Unable to query SQL to find pickedUp orders\00"
@.str.3 = [32 x i8] c"Unable to get pickedUp results.\00"
@.str.4 = [35 x i8] c"ERROR: Problem retrieving num_rows\00"
@.str.5 = [2 x i8] c"'\00"
@.str.6 = [15 x i8] c"' OR orderID='\00"
@.str.7 = [40 x i8] c"ERROR: Unable to update pickedup orders\00"
@.str.8 = [10 x i8] c"query: %s\00"
define i32 @cleanupPickedUp(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca [300 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i32* %0, i32** %3
store i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = load i32*, i32** %3
%12 = load i8*, i8** %9
%13 = call i64 @mysql_query(i32* %11, i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i32, i32* @LOG_INFO
%17 = call i32 (i32, i8*, ...) @syslog(i32 %16, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %82
18: ; preds = %1
%19 = load i32*, i32** %3
%20 = call i32* @mysql_store_result(i32* %19)
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @LOG_INFO
%25 = call i32 (i32, i8*, ...) @syslog(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %82
26: ; preds = %18
%27 = load i32*, i32** %7
%28 = call i32 @mysql_num_rows(i32* %27)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @LOG_INFO
%33 = call i32 (i32, i8*, ...) @syslog(i32 %32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %82
34: ; preds = %26
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 1, i32* %2
br label %82
38: ; preds = %34
%39 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%40 = load i8*, i8** %10
%41 = call i32 @strcpy(i8* %39, i8* %40)
br label %42
42: ; preds = %66, %38
%43 = load i32*, i32** %7
%44 = call i8** @mysql_fetch_row(i32* %43)
store i8** %44, i8*** %6
%45 = icmp ne i8** %44, null
br i1 %45, label %46, label %67
46: ; preds = %42
%47 = load i32, i32* %4
%48 = add nsw i32 %47, -1
store i32 %48, i32* %4
%49 = load i8**, i8*** %6
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 @deleteImageWithID(i8* %51)
%53 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%54 = load i8**, i8*** %6
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = call i32 @strcat(i8* %53, i8* %56)
%58 = load i32, i32* %4
%59 = icmp slt i32 %58, 1
br i1 %59, label %60, label %63
60: ; preds = %46
%61 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%62 = call i32 @strcat(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %66
63: ; preds = %46
%64 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %63, %60
br label %42
67: ; preds = %42
%68 = load i32*, i32** %3
%69 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%70 = call i64 @mysql_query(i32* %68, i8* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %67
%73 = load i32, i32* @LOG_INFO
%74 = call i32 (i32, i8*, ...) @syslog(i32 %73, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
%75 = load i32, i32* @LOG_INFO
%76 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%77 = call i32 (i32, i8*, ...) @syslog(i32 %75, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %76)
br label %79
78: ; preds = %67
br label %79
79: ; preds = %78, %72
%80 = load i32*, i32** %7
%81 = call i32 @mysql_free_result(i32* %80)
store i32 0, i32* %2
br label %82
82: ; preds = %79, %37, %31, %23, %15
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
@.str = [73 x i8] c"SELECT orderID FROM orderTable WHERE expired='false' AND pickedUp='true'\00"
@.str.1 = [53 x i8] c"UPDATE orderTable SET expired='true' WHERE orderID='\00"
@LOG_INFO = global i32 0
@.str.2 = [44 x i8] c"Unable to query SQL to find pickedUp orders\00"
@.str.3 = [32 x i8] c"Unable to get pickedUp results.\00"
@.str.4 = [35 x i8] c"ERROR: Problem retrieving num_rows\00"
@.str.5 = [2 x i8] c"'\00"
@.str.6 = [15 x i8] c"' OR orderID='\00"
@.str.7 = [40 x i8] c"ERROR: Unable to update pickedup orders\00"
@.str.8 = [10 x i8] c"query: %s\00"
define i32 @cleanupPickedUp(i32* %0) {
%2 = alloca [300 x i8]
%3 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @mysql_query(i32* %0, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @LOG_INFO
%8 = tail call i32 (i32, i8*, ...) @syslog(i32 %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %50
9: ; preds = %1
%10 = tail call i32* @mysql_store_result(i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @LOG_INFO
%14 = tail call i32 (i32, i8*, ...) @syslog(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %50
15: ; preds = %9
%16 = tail call i32 @mysql_num_rows(i32* %10)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @LOG_INFO
%20 = tail call i32 (i32, i8*, ...) @syslog(i32 %19, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %50
21: ; preds = %15
%22 = icmp eq i32 %16, 0
br i1 %22, label %50, label %23
23: ; preds = %21
%24 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%25 = call i8** @mysql_fetch_row(i32* %10)
%26 = icmp eq i8** %25, null
br i1 %26, label %40, label %27
27: ; preds = %23, %27
%28 = phi i8** [ %38, %27 ], [ %25, %23 ]
%29 = phi i32 [ %30, %27 ], [ %16, %23 ]
%30 = add nsw i32 %29, -1
%31 = load i8*, i8** %28
%32 = call i32 @deleteImageWithID(i8* %31)
%33 = load i8*, i8** %28
%34 = call i32 @strcat(i8* %3, i8* %33)
%35 = icmp slt i32 %29, 2
%36 = select i1 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0)
%37 = call i32 @strcat(i8* %3, i8* %36)
%38 = call i8** @mysql_fetch_row(i32* %10)
%39 = icmp eq i8** %38, null
br i1 %39, label %40, label %27
40: ; preds = %27, %23
%41 = call i64 @mysql_query(i32* %0, i8* %3)
%42 = icmp eq i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %40
%44 = load i32, i32* @LOG_INFO
%45 = call i32 (i32, i8*, ...) @syslog(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* @LOG_INFO
%47 = call i32 (i32, i8*, ...) @syslog(i32 %46, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %3)
br label %48
48: ; preds = %40, %43
%49 = call i32 @mysql_free_result(i32* %10)
br label %50
50: ; preds = %21, %48, %18, %12, %6
%51 = phi i32 [ 1, %6 ], [ 1, %12 ], [ 1, %18 ], [ 0, %48 ], [ 1, %21 ]
ret i32 %51
}