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

/* Variables and functions */
double RAND_MAX;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ check_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *do_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int mysql_num_rows(int /*<<< orphan*/ *);
float rand();
int /*<<< orphan*/ srand(int);
int time(int /*<<< orphan*/ *);
int /*<<< orphan*/ *vx_query(int /*<<< orphan*/ *, char *, ...);
int get_new_coords(MYSQL *mysql, int *x, int *y, int *z, int *gid) {
  MYSQL_RES *res;
  MYSQL_ROW row;
  int low = 1, high = 1, max_high = 0;
  int cnt = 0, rval;
  res = do_query(mysql, "SELECT x FROM galaxy ORDER BY x DESC LIMIT 1");
  row = mysql_fetch_row(res);
  max_high = atoi(row[0]);
  check_error(mysql);
  mysql_free_result(res);
  res = vx_query(mysql,
                 "SELECT x FROM galaxy WHERE members<%d AND !(x=1 AND y=1) "
                 "ORDER BY x ASC LIMIT 1",
                 7);
  if (!res || mysql_num_rows(res) < 1) {
    return 1;
  }
  row = mysql_fetch_row(res);
  low = atoi(row[0]);
  check_error(mysql);
  mysql_free_result(res);
  res = vx_query(mysql, "SELECT x FROM galaxy WHERE members>0 "
                        "ORDER BY x DESC LIMIT 1");
  row = mysql_fetch_row(res);
  high = atoi(row[0]);
  check_error(mysql);
  mysql_free_result(res);
  if (high < low)
    high = low;
  do {
    res = vx_query(mysql,
                   "SELECT x,y,id FROM galaxy WHERE x>=%d AND x<=%d "
                   "AND members<%d AND !(x=1 and y=1) GROUP BY x, y",
                   low, high, 7);
    if (!res)
      return 1;
    cnt = mysql_num_rows(res);
    if (cnt == 0) {
      low = high + 1;
      if (low > max_high)
        return 1;
      high = low;
    }
  } while (cnt == 0);
  if (cnt != 1) {
    srand((time(NULL) * (*gid + 1)));
    rval = 1 + (int)(((float)cnt - 1.) * rand() / (RAND_MAX + 1.0));
  } else {
    rval = 1;
  }
  while (rval > 1) {
    row = mysql_fetch_row(res);
    rval--;
  }
  row = mysql_fetch_row(res);
  *x = atoi(row[0]);
  *y = atoi(row[1]);
  *gid = atoi(row[2]);
  mysql_free_result(res);
  res = vx_query(mysql,
                 "SELECT z FROM planet WHERE x=%d AND y=%d "
                 "ORDER BY z DESC LIMIT 1",
                 *x, *y);
  if (res && mysql_num_rows(res)) {
    row = mysql_fetch_row(res);
    *z = 1 + atoi(row[0]);
  } else
    *z = 1;
  check_error(mysql);
  mysql_free_result(res);
  return 0;
}


x86 assembly (clang, -O0):
<get_new_coords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
movl   $0x1,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1050 <do_query@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <check_error@plt>
mov    -0x38(%rbp),%rdi
call   1090 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x7,%edx
mov    $0x0,%al
call   1030 <vx_query@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1251 <get_new_coords+0xb1>
mov    -0x38(%rbp),%rdi
call   10b0 <mysql_num_rows@plt>
cmp    $0x1,%eax
jge    125d <get_new_coords+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    14f2 <get_new_coords+0x352>
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <check_error@plt>
mov    -0x38(%rbp),%rdi
call   1090 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1030 <vx_query@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <check_error@plt>
mov    -0x38(%rbp),%rdi
call   1090 <mysql_free_result@plt>
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    12df <get_new_coords+0x13f>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    12e4 <get_new_coords+0x144>
mov    -0x10(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
lea    0xdcd(%rip),%rsi
mov    $0x7,%r8d
mov    $0x0,%al
call   1030 <vx_query@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    131d <get_new_coords+0x17d>
movl   $0x1,-0x4(%rbp)
jmp    14f2 <get_new_coords+0x352>
mov    -0x38(%rbp),%rdi
call   10b0 <mysql_num_rows@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jne    135a <get_new_coords+0x1ba>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jle    1354 <get_new_coords+0x1b4>
movl   $0x1,-0x4(%rbp)
jmp    14f2 <get_new_coords+0x352>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    135f <get_new_coords+0x1bf>
cmpl   $0x0,-0x50(%rbp)
je     12e4 <get_new_coords+0x144>
cmpl   $0x1,-0x50(%rbp)
je     13e6 <get_new_coords+0x246>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
imul   %eax,%edi
call   1060 <srand@plt>
cvtsi2ssl -0x50(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xc60(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xc38(%rip),%xmm1
mov    0x2c19(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    13ed <get_new_coords+0x24d>
movl   $0x1,-0x54(%rbp)
jmp    13f2 <get_new_coords+0x252>
cmpl   $0x1,-0x54(%rbp)
jle    1417 <get_new_coords+0x277>
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x54(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x54(%rbp)
jmp    13f2 <get_new_coords+0x252>
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
call   1090 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xca3(%rip),%rsi
mov    $0x0,%al
call   1030 <vx_query@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     14cf <get_new_coords+0x32f>
mov    -0x38(%rbp),%rdi
call   10b0 <mysql_num_rows@plt>
cmp    $0x0,%eax
je     14cf <get_new_coords+0x32f>
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    14d9 <get_new_coords+0x339>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rdi
call   1070 <check_error@plt>
mov    -0x38(%rbp),%rdi
call   1090 <mysql_free_result@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_new_coords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe4c(%rip),%rsi
call   1050 <do_query@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <mysql_fetch_row@plt>
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,(%rsp)
mov    %r14,%rdi
call   1070 <check_error@plt>
mov    %rbx,%rdi
call   1090 <mysql_free_result@plt>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
mov    $0x7,%edx
xor    %eax,%eax
call   1030 <vx_query@plt>
mov    %rax,%rbx
mov    $0x1,%eax
test   %rbx,%rbx
je     1406 <get_new_coords+0x266>
mov    %rbx,%rdi
call   10b0 <mysql_num_rows@plt>
test   %eax,%eax
jle    12da <get_new_coords+0x13a>
mov    %r13,0x10(%rsp)
mov    %rbp,0x18(%rsp)
mov    %r12,0x20(%rsp)
mov    %r15,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <mysql_fetch_row@plt>
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1070 <check_error@plt>
mov    %rbx,%rdi
call   1090 <mysql_free_result@plt>
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <vx_query@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <mysql_fetch_row@plt>
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1070 <check_error@plt>
mov    %rbx,%rdi
call   1090 <mysql_free_result@plt>
cmp    %ebp,%r12d
cmovl  %ebp,%r12d
lea    0xe2c(%rip),%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    $0x7,%r8d
xor    %eax,%eax
call   1030 <vx_query@plt>
test   %rax,%rax
je     12da <get_new_coords+0x13a>
mov    %rax,%r13
mov    %rax,%rdi
call   10b0 <mysql_num_rows@plt>
test   %eax,%eax
jne    12e4 <get_new_coords+0x144>
lea    0x1(%r12),%ebp
cmp    (%rsp),%r12d
mov    %ebp,%r12d
jl     12a0 <get_new_coords+0x100>
mov    $0x1,%eax
jmp    1406 <get_new_coords+0x266>
mov    %eax,%ebx
cmp    $0x1,%eax
je     1360 <get_new_coords+0x1c0>
xor    %edi,%edi
call   1080 <time@plt>
mov    0x10(%rsp),%rcx
mov    (%rcx),%edi
add    $0x1,%edi
imul   %eax,%edi
call   1060 <srand@plt>
cvtsi2ss %ebx,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xcec(%rip),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   10c0 <rand@plt>
cvtss2sd %xmm0,%xmm0
mulsd  (%rsp),%xmm0
mov    0x2cb8(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xccc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ebx
test   %ebx,%ebx
jle    1360 <get_new_coords+0x1c0>
add    $0x2,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <mysql_fetch_row@plt>
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
ja     1350 <get_new_coords+0x1b0>
mov    %r13,%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,%rbx
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    0x18(%rsp),%r15
mov    %eax,(%r15)
mov    0x4(%rbx),%edi
call   10a0 <atoi@plt>
mov    0x20(%rsp),%rbp
mov    %eax,0x0(%rbp)
mov    0x8(%rbx),%edi
call   10a0 <atoi@plt>
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
mov    %r13,%rdi
call   1090 <mysql_free_result@plt>
mov    (%r15),%edx
mov    0x0(%rbp),%ecx
lea    0xd7c(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <vx_query@plt>
mov    %rax,%rbp
mov    $0x1,%ebx
test   %rax,%rax
je     13ec <get_new_coords+0x24c>
mov    %rbp,%rdi
call   10b0 <mysql_num_rows@plt>
test   %eax,%eax
mov    0x8(%rsp),%r15
je     13f1 <get_new_coords+0x251>
mov    %rbp,%rdi
call   1040 <mysql_fetch_row@plt>
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,%ebx
add    $0x1,%ebx
jmp    13f1 <get_new_coords+0x251>
mov    0x8(%rsp),%r15
mov    %ebx,(%r15)
mov    %r14,%rdi
call   1070 <check_error@plt>
mov    %rbp,%rdi
call   1090 <mysql_free_result@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"SELECT x FROM galaxy ORDER BY x DESC LIMIT 1\00"
@.str.1 = [80 x i8] c"SELECT x FROM galaxy WHERE members<%d AND !(x=1 AND y=1) ORDER BY x ASC LIMIT 1\00"
@.str.2 = [61 x i8] c"SELECT x FROM galaxy WHERE members>0 ORDER BY x DESC LIMIT 1\00"
@.str.3 = [96 x i8] c"SELECT x,y,id FROM galaxy WHERE x>=%d AND x<=%d AND members<%d AND !(x=1 and y=1) GROUP BY x, y\00"
@RAND_MAX = global double 0.000000e+00
@.str.4 = [65 x i8] c"SELECT z FROM planet WHERE x=%d AND y=%d ORDER BY z DESC LIMIT 1\00"
define i32 @get_new_coords(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32 1, i32* %14
store i32 1, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
%19 = load i32*, i32** %7
%20 = call i32* @do_query(i32* %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %12
%21 = load i32*, i32** %12
%22 = call i32* @mysql_fetch_row(i32* %21)
store i32* %22, i32** %13
%23 = load i32*, i32** %13
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %16
%27 = load i32*, i32** %7
%28 = call i32 @check_error(i32* %27)
%29 = load i32*, i32** %12
%30 = call i32 @mysql_free_result(i32* %29)
%31 = load i32*, i32** %7
%32 = call i32* (i32*, i8*, ...) @vx_query(i32* %31, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i32 7)
store i32* %32, i32** %12
%33 = load i32*, i32** %12
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %5
%36 = load i32*, i32** %12
%37 = call i32 @mysql_num_rows(i32* %36)
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %35, %5
store i32 1, i32* %6
br label %175
40: ; preds = %35
%41 = load i32*, i32** %12
%42 = call i32* @mysql_fetch_row(i32* %41)
store i32* %42, i32** %13
%43 = load i32*, i32** %13
%44 = getelementptr inbounds i32, i32* %43, i64 0
%45 = load i32, i32* %44
%46 = call i32 @atoi(i32 %45)
store i32 %46, i32* %14
%47 = load i32*, i32** %7
%48 = call i32 @check_error(i32* %47)
%49 = load i32*, i32** %12
%50 = call i32 @mysql_free_result(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32* (i32*, i8*, ...) @vx_query(i32* %51, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i32* %52, i32** %12
%53 = load i32*, i32** %12
%54 = call i32* @mysql_fetch_row(i32* %53)
store i32* %54, i32** %13
%55 = load i32*, i32** %13
%56 = getelementptr inbounds i32, i32* %55, i64 0
%57 = load i32, i32* %56
%58 = call i32 @atoi(i32 %57)
store i32 %58, i32* %15
%59 = load i32*, i32** %7
%60 = call i32 @check_error(i32* %59)
%61 = load i32*, i32** %12
%62 = call i32 @mysql_free_result(i32* %61)
%63 = load i32, i32* %15
%64 = load i32, i32* %14
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %68
66: ; preds = %40
%67 = load i32, i32* %14
store i32 %67, i32* %15
br label %68
68: ; preds = %66, %40
br label %69
69: ; preds = %92, %68
%70 = load i32*, i32** %7
%71 = load i32, i32* %14
%72 = load i32, i32* %15
%73 = call i32* (i32*, i8*, ...) @vx_query(i32* %70, i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0), i32 %71, i32 %72, i32 7)
store i32* %73, i32** %12
%74 = load i32*, i32** %12
%75 = icmp ne i32* %74, null
br i1 %75, label %77, label %76
76: ; preds = %69
store i32 1, i32* %6
br label %175
77: ; preds = %69
%78 = load i32*, i32** %12
%79 = call i32 @mysql_num_rows(i32* %78)
store i32 %79, i32* %17
%80 = load i32, i32* %17
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %91
82: ; preds = %77
%83 = load i32, i32* %15
%84 = add nsw i32 %83, 1
store i32 %84, i32* %14
%85 = load i32, i32* %14
%86 = load i32, i32* %16
%87 = icmp sgt i32 %85, %86
br i1 %87, label %88, label %89
88: ; preds = %82
store i32 1, i32* %6
br label %175
89: ; preds = %82
%90 = load i32, i32* %14
store i32 %90, i32* %15
br label %91
91: ; preds = %89, %77
br label %92
92: ; preds = %91
%93 = load i32, i32* %17
%94 = icmp eq i32 %93, 0
br i1 %94, label %69, label %95
95: ; preds = %92
%96 = load i32, i32* %17
%97 = icmp ne i32 %96, 1
br i1 %97, label %98, label %117
98: ; preds = %95
%99 = call i32 @time(i32* null)
%100 = load i32*, i32** %11
%101 = load i32, i32* %100
%102 = add nsw i32 %101, 1
%103 = mul nsw i32 %99, %102
%104 = call i32 @srand(i32 %103)
%105 = load i32, i32* %17
%106 = sitofp i32 %105 to float
%107 = fpext float %106 to double
%108 = fsub double %107, 1.000000e+00
%109 = call float (...) @rand()
%110 = fpext float %109 to double
%111 = fmul double %108, %110
%112 = load double, double* @RAND_MAX
%113 = fadd double %112, 1.000000e+00
%114 = fdiv double %111, %113
%115 = fptosi double %114 to i32
%116 = add nsw i32 1, %115
store i32 %116, i32* %18
br label %118
117: ; preds = %95
store i32 1, i32* %18
br label %118
118: ; preds = %117, %98
br label %119
119: ; preds = %122, %118
%120 = load i32, i32* %18
%121 = icmp sgt i32 %120, 1
br i1 %121, label %122, label %127
122: ; preds = %119
%123 = load i32*, i32** %12
%124 = call i32* @mysql_fetch_row(i32* %123)
store i32* %124, i32** %13
%125 = load i32, i32* %18
%126 = add nsw i32 %125, -1
store i32 %126, i32* %18
br label %119
127: ; preds = %119
%128 = load i32*, i32** %12
%129 = call i32* @mysql_fetch_row(i32* %128)
store i32* %129, i32** %13
%130 = load i32*, i32** %13
%131 = getelementptr inbounds i32, i32* %130, i64 0
%132 = load i32, i32* %131
%133 = call i32 @atoi(i32 %132)
%134 = load i32*, i32** %8
store i32 %133, i32* %134
%135 = load i32*, i32** %13
%136 = getelementptr inbounds i32, i32* %135, i64 1
%137 = load i32, i32* %136
%138 = call i32 @atoi(i32 %137)
%139 = load i32*, i32** %9
store i32 %138, i32* %139
%140 = load i32*, i32** %13
%141 = getelementptr inbounds i32, i32* %140, i64 2
%142 = load i32, i32* %141
%143 = call i32 @atoi(i32 %142)
%144 = load i32*, i32** %11
store i32 %143, i32* %144
%145 = load i32*, i32** %12
%146 = call i32 @mysql_free_result(i32* %145)
%147 = load i32*, i32** %7
%148 = load i32*, i32** %8
%149 = load i32, i32* %148
%150 = load i32*, i32** %9
%151 = load i32, i32* %150
%152 = call i32* (i32*, i8*, ...) @vx_query(i32* %147, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %149, i32 %151)
store i32* %152, i32** %12
%153 = load i32*, i32** %12
%154 = icmp ne i32* %153, null
br i1 %154, label %155, label %168
155: ; preds = %127
%156 = load i32*, i32** %12
%157 = call i32 @mysql_num_rows(i32* %156)
%158 = icmp ne i32 %157, 0
br i1 %158, label %159, label %168
159: ; preds = %155
%160 = load i32*, i32** %12
%161 = call i32* @mysql_fetch_row(i32* %160)
store i32* %161, i32** %13
%162 = load i32*, i32** %13
%163 = getelementptr inbounds i32, i32* %162, i64 0
%164 = load i32, i32* %163
%165 = call i32 @atoi(i32 %164)
%166 = add nsw i32 1, %165
%167 = load i32*, i32** %10
store i32 %166, i32* %167
br label %170
168: ; preds = %155, %127
%169 = load i32*, i32** %10
store i32 1, i32* %169
br label %170
170: ; preds = %168, %159
%171 = load i32*, i32** %7
%172 = call i32 @check_error(i32* %171)
%173 = load i32*, i32** %12
%174 = call i32 @mysql_free_result(i32* %173)
store i32 0, i32* %6
br label %175
175: ; preds = %170, %88, %76, %39
%176 = load i32, i32* %6
ret i32 %176
}

LLVM IR (-O2):
@.str = [45 x i8] c"SELECT x FROM galaxy ORDER BY x DESC LIMIT 1\00"
@.str.1 = [80 x i8] c"SELECT x FROM galaxy WHERE members<%d AND !(x=1 AND y=1) ORDER BY x ASC LIMIT 1\00"
@.str.2 = [61 x i8] c"SELECT x FROM galaxy WHERE members>0 ORDER BY x DESC LIMIT 1\00"
@.str.3 = [96 x i8] c"SELECT x,y,id FROM galaxy WHERE x>=%d AND x<=%d AND members<%d AND !(x=1 and y=1) GROUP BY x, y\00"
@RAND_MAX = global double 0.000000e+00
@.str.4 = [65 x i8] c"SELECT z FROM planet WHERE x=%d AND y=%d ORDER BY z DESC LIMIT 1\00"
define i32 @get_new_coords(i32* %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3, i32* nocapture %4) {
%6 = tail call i32* @do_query(i32* %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @mysql_fetch_row(i32* %6)
%8 = load i32, i32* %7
%9 = tail call i32 @atoi(i32 %8)
%10 = tail call i32 @check_error(i32* %0)
%11 = tail call i32 @mysql_free_result(i32* %6)
%12 = tail call i32* (i32*, i8*, ...) @vx_query(i32* %0, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i32 7)
%13 = icmp eq i32* %12, null
br i1 %13, label %92, label %14
14: ; preds = %5
%15 = tail call i32 @mysql_num_rows(i32* %12)
%16 = icmp slt i32 %15, 1
br i1 %16, label %92, label %17
17: ; preds = %14
%18 = tail call i32* @mysql_fetch_row(i32* %12)
%19 = load i32, i32* %18
%20 = tail call i32 @atoi(i32 %19)
%21 = tail call i32 @check_error(i32* %0)
%22 = tail call i32 @mysql_free_result(i32* %12)
%23 = tail call i32* (i32*, i8*, ...) @vx_query(i32* %0, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32* @mysql_fetch_row(i32* %23)
%25 = load i32, i32* %24
%26 = tail call i32 @atoi(i32 %25)
%27 = tail call i32 @check_error(i32* %0)
%28 = tail call i32 @mysql_free_result(i32* %23)
%29 = icmp slt i32 %26, %20
%30 = select i1 %29, i32 %20, i32 %26
br label %31
31: ; preds = %38, %17
%32 = phi i32 [ %20, %17 ], [ %39, %38 ]
%33 = phi i32 [ %30, %17 ], [ %39, %38 ]
%34 = tail call i32* (i32*, i8*, ...) @vx_query(i32* %0, i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33, i32 7)
%35 = icmp eq i32* %34, null
br i1 %35, label %92, label %36
36: ; preds = %31
%37 = tail call i32 @mysql_num_rows(i32* %34)
switch i32 %37, label %41 [
i32 0, label %38
i32 1, label %65
]
38: ; preds = %36
%39 = add nsw i32 %33, 1
%40 = icmp slt i32 %33, %9
br i1 %40, label %31, label %92
41: ; preds = %36
%42 = tail call i32 @time(i32* null)
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
%45 = mul nsw i32 %44, %42
%46 = tail call i32 @srand(i32 %45)
%47 = sitofp i32 %37 to float
%48 = fpext float %47 to double
%49 = fadd double %48, -1.000000e+00
%50 = tail call float (...) @rand()
%51 = fpext float %50 to double
%52 = fmul double %49, %51
%53 = load double, double* @RAND_MAX
%54 = fadd double %53, 1.000000e+00
%55 = fdiv double %52, %54
%56 = fptosi double %55 to i32
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %41
%59 = add nsw i32 %56, 1
br label %60
60: ; preds = %58, %60
%61 = phi i32 [ %63, %60 ], [ %59, %58 ]
%62 = tail call i32* @mysql_fetch_row(i32* %34)
%63 = add nsw i32 %61, -1
%64 = icmp ugt i32 %61, 2
br i1 %64, label %60, label %65
65: ; preds = %36, %60, %41
%66 = tail call i32* @mysql_fetch_row(i32* %34)
%67 = load i32, i32* %66
%68 = tail call i32 @atoi(i32 %67)
store i32 %68, i32* %1
%69 = getelementptr inbounds i32, i32* %66, i64 1
%70 = load i32, i32* %69
%71 = tail call i32 @atoi(i32 %70)
store i32 %71, i32* %2
%72 = getelementptr inbounds i32, i32* %66, i64 2
%73 = load i32, i32* %72
%74 = tail call i32 @atoi(i32 %73)
store i32 %74, i32* %4
%75 = tail call i32 @mysql_free_result(i32* %34)
%76 = load i32, i32* %1
%77 = load i32, i32* %2
%78 = tail call i32* (i32*, i8*, ...) @vx_query(i32* %0, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.4, i64 0, i64 0), i32 %76, i32 %77)
%79 = icmp eq i32* %78, null
br i1 %79, label %88, label %80
80: ; preds = %65
%81 = tail call i32 @mysql_num_rows(i32* %78)
%82 = icmp eq i32 %81, 0
br i1 %82, label %88, label %83
83: ; preds = %80
%84 = tail call i32* @mysql_fetch_row(i32* %78)
%85 = load i32, i32* %84
%86 = tail call i32 @atoi(i32 %85)
%87 = add nsw i32 %86, 1
br label %88
88: ; preds = %65, %80, %83
%89 = phi i32 [ %87, %83 ], [ 1, %80 ], [ 1, %65 ]
store i32 %89, i32* %3
%90 = tail call i32 @check_error(i32* %0)
%91 = tail call i32 @mysql_free_result(i32* %78)
br label %92
92: ; preds = %38, %31, %5, %14, %88
%93 = phi i32 [ 0, %88 ], [ 1, %14 ], [ 1, %5 ], [ 1, %31 ], [ 1, %38 ]
ret i32 %93
}