#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 *getenv(char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
int ora_init_vars2(char *username, char *password, char *dbspec, size_t size) {
  if (!size)
    return -1;
  const char *e = getenv("ORACLE_USER");
  if (e)
    strncpy(username, e, size - 1);
  else
    return -2;
  e = getenv("ORACLE_PASS");
  if (e)
    strncpy(password, e, size - 1);
  else
    return -2;
  e = getenv("ORACLE_SID");
  if (e)
    strncpy(dbspec, e, size - 1);
  else
    return -2;
  return 0;
}


x86 assembly (clang, -O0):
<ora_init_vars2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    114f <ora_init_vars2+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1219 <ora_init_vars2+0xf9>
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1184 <ora_init_vars2+0x64>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <strncpy@plt>
jmp    1190 <ora_init_vars2+0x70>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1219 <ora_init_vars2+0xf9>
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c5 <ora_init_vars2+0xa5>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <strncpy@plt>
jmp    11d1 <ora_init_vars2+0xb1>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1219 <ora_init_vars2+0xf9>
lea    0xe40(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1206 <ora_init_vars2+0xe6>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <strncpy@plt>
jmp    1212 <ora_init_vars2+0xf2>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1219 <ora_init_vars2+0xf9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ora_init_vars2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rcx,%rcx
je     11a5 <ora_init_vars2+0x85>
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xec0(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xfffffffe,%r12d
test   %rax,%rax
je     11ab <ora_init_vars2+0x8b>
add    $0xffffffffffffffff,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ab <ora_init_vars2+0x8b>
mov    %r15,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
lea    0xe90(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ab <ora_init_vars2+0x8b>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
xor    %r12d,%r12d
jmp    11ab <ora_init_vars2+0x8b>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ORACLE_USER\00"
@.str.1 = [12 x i8] c"ORACLE_PASS\00"
@.str.2 = [11 x i8] c"ORACLE_SID\00"
define i32 @ora_init_vars2(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i64, i64* %9
%12 = icmp ne i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %4
store i32 -1, i32* %5
br label %48
14: ; preds = %4
%15 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i8*, i8** %10
%21 = load i64, i64* %9
%22 = sub i64 %21, 1
%23 = call i32 @strncpy(i8* %19, i8* %20, i64 %22)
br label %25
24: ; preds = %14
store i32 -2, i32* %5
br label %48
25: ; preds = %18
%26 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %10
%27 = load i8*, i8** %10
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = load i8*, i8** %10
%32 = load i64, i64* %9
%33 = sub i64 %32, 1
%34 = call i32 @strncpy(i8* %30, i8* %31, i64 %33)
br label %36
35: ; preds = %25
store i32 -2, i32* %5
br label %48
36: ; preds = %29
%37 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i8*, i8** %8
%42 = load i8*, i8** %10
%43 = load i64, i64* %9
%44 = sub i64 %43, 1
%45 = call i32 @strncpy(i8* %41, i8* %42, i64 %44)
br label %47
46: ; preds = %36
store i32 -2, i32* %5
br label %48
47: ; preds = %40
store i32 0, i32* %5
br label %48
48: ; preds = %47, %46, %35, %24, %13
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [12 x i8] c"ORACLE_USER\00"
@.str.1 = [12 x i8] c"ORACLE_PASS\00"
@.str.2 = [11 x i8] c"ORACLE_SID\00"
define i32 @ora_init_vars2(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = icmp eq i64 %3, 0
br i1 %5, label %20, label %6
6: ; preds = %4
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = add i64 %3, -1
%11 = tail call i32 @strncpy(i8* %0, i8* %7, i64 %10)
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %9
%15 = tail call i32 @strncpy(i8* %1, i8* %12, i64 %10)
%16 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @strncpy(i8* %2, i8* %16, i64 %10)
br label %20
20: ; preds = %18, %6, %9, %14, %4
%21 = phi i32 [ -1, %4 ], [ 0, %18 ], [ -2, %6 ], [ -2, %9 ], [ -2, %14 ]
ret i32 %21
}