#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 */
int /*<<< orphan*/ MYSQL_PORT;
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                       char *, char *, int /*<<< orphan*/,
                                       int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ workBD(int /*<<< orphan*/, int);
int readBD(char **argv) {
  int i = 0;
  MYSQL *database;
  if ((database = mysql_init(0)) == NULL) {
    return 1;
  }
  if ((mysql_real_connect(database, argv[2], argv[3], argv[4], argv[1],
                          MYSQL_PORT, NULL, 0)) == NULL) {
    return 2;
  }
  char *table =
      "select TEMP,TM,Tmin,PREC,HUM,NIEV,TOR,NIEB,HEL,DESP,SOL,cultivo from "
      "metereo,culter;";
  MYSQL_ROW row;
  if ((mysql_query(database, table)) == 0) {
    MYSQL_RES *resultado;
    while (row = mysql_fetch_row(resultado)) {
      i = i + 1;
    }
  }
  mysql_close(database);
  if (i <= 0) {
    return 3;
  }
  workBD(row, i);
  return 0;
}


x86 assembly (clang, -O0):
<readBD>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %edi,%edi
call   1070 <mysql_init@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1194 <readBD+0x34>
movl   $0x1,-0x4(%rbp)
jmp    1271 <readBD+0x111>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
mov    0x2e21(%rip),%rax
mov    (%rax),%r9d
xor    %eax,%eax
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <mysql_real_connect@plt>
cmp    $0x0,%rax
jne    11f1 <readBD+0x91>
movl   $0x2,-0x4(%rbp)
jmp    1271 <readBD+0x111>
lea    0xe08(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
jne    1240 <readBD+0xe0>
jmp    1218 <readBD+0xb8>
mov    -0x38(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     123b <readBD+0xdb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1218 <readBD+0xb8>
jmp    1240 <readBD+0xe0>
mov    -0x20(%rbp),%rdi
call   1060 <mysql_close@plt>
cmpl   $0x0,-0x14(%rbp)
jg     125f <readBD+0xff>
movl   $0x3,-0x4(%rbp)
jmp    1271 <readBD+0x111>
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1080 <workBD@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBD>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
xor    %edi,%edi
call   1070 <mysql_init@plt>
test   %rax,%rax
je     11c7 <readBD+0x67>
mov    %rax,%rbx
mov    0x8(%rbp),%r8
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    0x20(%rbp),%rcx
mov    0x2e54(%rip),%rax
mov    (%rax),%r9d
mov    %rbx,%rdi
push   $0x0
push   $0x0
call   1050 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11ce <readBD+0x6e>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1030 <mysql_query@plt>
test   %rax,%rax
je     11d5 <readBD+0x75>
mov    %rbx,%rdi
call   1060 <mysql_close@plt>
mov    $0x3,%ebx
jmp    1205 <readBD+0xa5>
mov    $0x1,%ebx
jmp    1205 <readBD+0xa5>
mov    $0x2,%ebx
jmp    1205 <readBD+0xa5>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
call   1040 <mysql_fetch_row@plt>
add    $0xffffffff,%ebp
test   %eax,%eax
jne    11e0 <readBD+0x80>
mov    %rbx,%rdi
call   1060 <mysql_close@plt>
test   %ebp,%ebp
je     11c0 <readBD+0x60>
neg    %ebp
xor    %ebx,%ebx
xor    %edi,%edi
mov    %ebp,%esi
call   1080 <workBD@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@MYSQL_PORT = global i32 0
@.str = [85 x i8] c"select TEMP,TM,Tmin,PREC,HUM,NIEV,TOR,NIEB,HEL,DESP,SOL,cultivo from metereo,culter;\00"
define i32 @readBD(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
store i8** %0, i8*** %3
store i32 0, i32* %4
%9 = call i32* @mysql_init(i32 0)
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %54
12: ; preds = %1
%13 = load i32*, i32** %5
%14 = load i8**, i8*** %3
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %3
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 4
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @MYSQL_PORT
%27 = call i32* @mysql_real_connect(i32* %13, i8* %16, i8* %19, i8* %22, i8* %25, i32 %26, i32* null, i32 0)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %12
store i32 2, i32* %2
br label %54
30: ; preds = %12
store i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i8** %6
%31 = load i32*, i32** %5
%32 = load i8*, i8** %6
%33 = call i64 @mysql_query(i32* %31, i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %30
br label %36
36: ; preds = %40, %35
%37 = load i32*, i32** %8
%38 = call i32 @mysql_fetch_row(i32* %37)
store i32 %38, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %36
43: ; preds = %36
br label %44
44: ; preds = %43, %30
%45 = load i32*, i32** %5
%46 = call i32 @mysql_close(i32* %45)
%47 = load i32, i32* %4
%48 = icmp sle i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 3, i32* %2
br label %54
50: ; preds = %44
%51 = load i32, i32* %7
%52 = load i32, i32* %4
%53 = call i32 @workBD(i32 %51, i32 %52)
store i32 0, i32* %2
br label %54
54: ; preds = %50, %49, %29, %11
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
@MYSQL_PORT = global i32 0
@.str = [85 x i8] c"select TEMP,TM,Tmin,PREC,HUM,NIEV,TOR,NIEB,HEL,DESP,SOL,cultivo from metereo,culter;\00"
define i32 @readBD(i8** nocapture %0) {
%2 = tail call i32* @mysql_init(i32 0)
%3 = icmp eq i32* %2, null
br i1 %3, label %31, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8*, i8** %0, i64 2
%6 = load i8*, i8** %5
%7 = getelementptr inbounds i8*, i8** %0, i64 3
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %0, i64 4
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %0, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @MYSQL_PORT
%14 = tail call i32* @mysql_real_connect(i32* %2, i8* %6, i8* %8, i8* %10, i8* %12, i32 %13, i32* null, i32 0)
%15 = icmp eq i32* %14, null
br i1 %15, label %31, label %16
16: ; preds = %4
%17 = tail call i64 @mysql_query(i32* %2, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @mysql_close(i32* %2)
br label %31
21: ; preds = %16, %21
%22 = phi i32 [ %25, %21 ], [ 0, %16 ]
%23 = tail call i32 @mysql_fetch_row(i32* undef)
%24 = icmp eq i32 %23, 0
%25 = add nuw nsw i32 %22, 1
br i1 %24, label %26, label %21
26: ; preds = %21
%27 = tail call i32 @mysql_close(i32* %2)
%28 = icmp eq i32 %22, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = tail call i32 @workBD(i32 0, i32 %22)
br label %31
31: ; preds = %19, %29, %26, %4, %1
%32 = phi i32 [ 1, %1 ], [ 2, %4 ], [ 0, %29 ], [ 3, %26 ], [ 3, %19 ]
ret i32 %32
}