#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 */
struct sqlca_t {
  int dummy;
};

/* Variables and functions */
int _ocesqlConnectMain(struct sqlca_t *, char *, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_str_without_after_space(int /*<<< orphan*/);
int /*<<< orphan*/ oc_strndup(char *, int);
char *ocdb_getenv(char *, int /*<<< orphan*/ *);
char *strdup(char *);
scalar_t__ strlen(char *);
int _ocesqlConnect(struct sqlca_t *st, char *user, int userlen, char *passwd,
                   int passwdlen, char *name, int namelen, char *atdb) {
  char *dbuser, *dbpasswd, *dbname;
  char *tmpuser, *tmppasswd, *tmpname;
  int ret;
  tmpname = ocdb_getenv("OCDB_DB_NAME", NULL);
  tmpuser = ocdb_getenv("OCDB_DB_USER", NULL);
  tmppasswd = ocdb_getenv("OCDB_DB_PASS", NULL);
  if (((dbname = get_str_without_after_space(oc_strndup(name, namelen))) ==
       NULL) ||
      (strlen(dbname) <= 0)) {
    if (tmpname)
      dbname = strdup(tmpname);
  }
  if (((dbuser = get_str_without_after_space(oc_strndup(user, userlen))) ==
       NULL) ||
      (strlen(dbuser) <= 0)) {
    if (tmpuser)
      dbuser = strdup(tmpuser);
  }
  if (((dbpasswd = get_str_without_after_space(
            oc_strndup(passwd, passwdlen))) == NULL) ||
      (strlen(dbpasswd) <= 0)) {
    if (tmppasswd)
      dbpasswd = strdup(tmppasswd);
  }
  ret = _ocesqlConnectMain(st, dbname, dbuser, dbpasswd, "OCDB_DEFAULT_DBNAME");
  free(dbname);
  free(dbuser);
  free(dbpasswd);
  return ret;
}


x86 assembly (clang, -O0):
<_ocesqlConnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
lea    0xe63(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,-0x60(%rbp)
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,-0x50(%rbp)
lea    0xe55(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x10(%rbp),%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     1206 <_ocesqlConnect+0x96>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jg     1223 <_ocesqlConnect+0xb3>
cmpq   $0x0,-0x60(%rbp)
je     121e <_ocesqlConnect+0xae>
mov    -0x60(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x48(%rbp)
jmp    1223 <_ocesqlConnect+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1257 <_ocesqlConnect+0xe7>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jg     1274 <_ocesqlConnect+0x104>
cmpq   $0x0,-0x50(%rbp)
je     126f <_ocesqlConnect+0xff>
mov    -0x50(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
jmp    1274 <_ocesqlConnect+0x104>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     12a8 <_ocesqlConnect+0x138>
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jg     12c5 <_ocesqlConnect+0x155>
cmpq   $0x0,-0x58(%rbp)
je     12c0 <_ocesqlConnect+0x150>
mov    -0x58(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x40(%rbp)
jmp    12c5 <_ocesqlConnect+0x155>
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd4b(%rip),%r8
call   1090 <_ocesqlConnectMain@plt>
mov    %eax,-0x64(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ocesqlConnect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%rbx
mov    %r8d,0xc(%rsp)
mov    %rcx,0x20(%rsp)
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
mov    0x60(%rsp),%r15d
lea    0xe60(%rip),%rdi
xor    %esi,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,%r13
lea    0xe5c(%rip),%rdi
xor    %esi,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,0x10(%rsp)
lea    0xe56(%rip),%rdi
xor    %esi,%esi
call   1040 <ocdb_getenv@plt>
mov    %rax,0x18(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
test   %rax,%rax
je     1202 <_ocesqlConnect+0x92>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     1218 <_ocesqlConnect+0xa8>
test   %r13,%r13
mov    0xc(%rsp),%ebx
jne    120b <_ocesqlConnect+0x9b>
jmp    1221 <_ocesqlConnect+0xb1>
test   %r13,%r13
mov    0xc(%rsp),%ebx
je     121e <_ocesqlConnect+0xae>
mov    %r13,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
jmp    1221 <_ocesqlConnect+0xb1>
mov    0xc(%rsp),%ebx
jmp    1221 <_ocesqlConnect+0xb1>
xor    %r15d,%r15d
mov    %r12,%rdi
mov    %r14d,%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
test   %rax,%rax
je     1254 <_ocesqlConnect+0xe4>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     126b <_ocesqlConnect+0xfb>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
jne    125e <_ocesqlConnect+0xee>
jmp    126b <_ocesqlConnect+0xfb>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1268 <_ocesqlConnect+0xf8>
call   1080 <strdup@plt>
mov    %rax,%r12
jmp    126b <_ocesqlConnect+0xfb>
xor    %r12d,%r12d
mov    0x20(%rsp),%rdi
mov    %ebx,%esi
call   1060 <oc_strndup@plt>
mov    %eax,%edi
call   1070 <get_str_without_after_space@plt>
test   %rax,%rax
je     129f <_ocesqlConnect+0x12f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jg     12b5 <_ocesqlConnect+0x145>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
jne    12a9 <_ocesqlConnect+0x139>
jmp    12b5 <_ocesqlConnect+0x145>
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
je     12b3 <_ocesqlConnect+0x143>
call   1080 <strdup@plt>
mov    %rax,%rbx
jmp    12b5 <_ocesqlConnect+0x145>
xor    %ebx,%ebx
lea    0xd6b(%rip),%r8
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1090 <_ocesqlConnectMain@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sqlca_t = type { i32 }
@.str = [13 x i8] c"OCDB_DB_NAME\00"
@.str.1 = [13 x i8] c"OCDB_DB_USER\00"
@.str.2 = [13 x i8] c"OCDB_DB_PASS\00"
@.str.3 = [20 x i8] c"OCDB_DEFAULT_DBNAME\00"
define i32 @_ocesqlConnect(%struct.sqlca_t* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5, i32 %6, i8* %7) {
%9 = alloca %struct.sqlca_t*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i32
store %struct.sqlca_t* %0, %struct.sqlca_t** %9
store i8* %1, i8** %10
store i32 %2, i32* %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i8* %5, i8** %14
store i32 %6, i32* %15
store i8* %7, i8** %16
%24 = call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null)
store i8* %24, i8** %22
%25 = call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* null)
store i8* %25, i8** %20
%26 = call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* null)
store i8* %26, i8** %21
%27 = load i8*, i8** %14
%28 = load i32, i32* %15
%29 = call i32 @oc_strndup(i8* %27, i32 %28)
%30 = call i8* @get_str_without_after_space(i32 %29)
store i8* %30, i8** %19
%31 = icmp eq i8* %30, null
br i1 %31, label %36, label %32
32: ; preds = %8
%33 = load i8*, i8** %19
%34 = call i64 @strlen(i8* %33)
%35 = icmp sle i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %32, %8
%37 = load i8*, i8** %22
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %22
%41 = call i8* @strdup(i8* %40)
store i8* %41, i8** %19
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42, %32
%44 = load i8*, i8** %10
%45 = load i32, i32* %11
%46 = call i32 @oc_strndup(i8* %44, i32 %45)
%47 = call i8* @get_str_without_after_space(i32 %46)
store i8* %47, i8** %17
%48 = icmp eq i8* %47, null
br i1 %48, label %53, label %49
49: ; preds = %43
%50 = load i8*, i8** %17
%51 = call i64 @strlen(i8* %50)
%52 = icmp sle i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %49, %43
%54 = load i8*, i8** %20
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %20
%58 = call i8* @strdup(i8* %57)
store i8* %58, i8** %17
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %49
%61 = load i8*, i8** %12
%62 = load i32, i32* %13
%63 = call i32 @oc_strndup(i8* %61, i32 %62)
%64 = call i8* @get_str_without_after_space(i32 %63)
store i8* %64, i8** %18
%65 = icmp eq i8* %64, null
br i1 %65, label %70, label %66
66: ; preds = %60
%67 = load i8*, i8** %18
%68 = call i64 @strlen(i8* %67)
%69 = icmp sle i64 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %66, %60
%71 = load i8*, i8** %21
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i8*, i8** %21
%75 = call i8* @strdup(i8* %74)
store i8* %75, i8** %18
br label %76
76: ; preds = %73, %70
br label %77
77: ; preds = %76, %66
%78 = load %struct.sqlca_t*, %struct.sqlca_t** %9
%79 = load i8*, i8** %19
%80 = load i8*, i8** %17
%81 = load i8*, i8** %18
%82 = call i32 @_ocesqlConnectMain(%struct.sqlca_t* %78, i8* %79, i8* %80, i8* %81, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 %82, i32* %23
%83 = load i8*, i8** %19
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %17
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %18
%88 = call i32 @free(i8* %87)
%89 = load i32, i32* %23
ret i32 %89
}

LLVM IR (-O2):
%struct.sqlca_t = type { i32 }
@.str = [13 x i8] c"OCDB_DB_NAME\00"
@.str.1 = [13 x i8] c"OCDB_DB_USER\00"
@.str.2 = [13 x i8] c"OCDB_DB_PASS\00"
@.str.3 = [20 x i8] c"OCDB_DEFAULT_DBNAME\00"
define i32 @_ocesqlConnect(%struct.sqlca_t* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5, i32 %6, i8* nocapture readnone %7) {
%9 = tail call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null)
%10 = tail call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* null)
%11 = tail call i8* @ocdb_getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* null)
%12 = tail call i32 @oc_strndup(i8* %5, i32 %6)
%13 = tail call i8* @get_str_without_after_space(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %8
%16 = tail call i64 @strlen(i8* %13)
%17 = icmp slt i64 %16, 1
%18 = icmp ne i8* %9, null
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %22, label %24
20: ; preds = %8
%21 = icmp eq i8* %9, null
br i1 %21, label %24, label %22
22: ; preds = %15, %20
%23 = tail call i8* @strdup(i8* %9)
br label %24
24: ; preds = %20, %22, %15
%25 = phi i8* [ %23, %22 ], [ null, %20 ], [ %13, %15 ]
%26 = tail call i32 @oc_strndup(i8* %1, i32 %2)
%27 = tail call i8* @get_str_without_after_space(i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = tail call i64 @strlen(i8* %27)
%31 = icmp slt i64 %30, 1
%32 = icmp ne i8* %10, null
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %36, label %38
34: ; preds = %24
%35 = icmp eq i8* %10, null
br i1 %35, label %38, label %36
36: ; preds = %29, %34
%37 = tail call i8* @strdup(i8* %10)
br label %38
38: ; preds = %34, %36, %29
%39 = phi i8* [ %37, %36 ], [ null, %34 ], [ %27, %29 ]
%40 = tail call i32 @oc_strndup(i8* %3, i32 %4)
%41 = tail call i8* @get_str_without_after_space(i32 %40)
%42 = icmp eq i8* %41, null
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = tail call i64 @strlen(i8* %41)
%45 = icmp slt i64 %44, 1
%46 = icmp ne i8* %11, null
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %50, label %52
48: ; preds = %38
%49 = icmp eq i8* %11, null
br i1 %49, label %52, label %50
50: ; preds = %43, %48
%51 = tail call i8* @strdup(i8* %11)
br label %52
52: ; preds = %48, %50, %43
%53 = phi i8* [ %51, %50 ], [ null, %48 ], [ %41, %43 ]
%54 = tail call i32 @_ocesqlConnectMain(%struct.sqlca_t* %0, i8* %25, i8* %39, i8* %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%55 = tail call i32 @free(i8* %25)
%56 = tail call i32 @free(i8* %39)
%57 = tail call i32 @free(i8* %53)
ret i32 %54
}