#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 */
int /*<<< orphan*/ sprintf(char *, char *);
char *strdup(char *);
char *environ_get_shell_snippet(void) {
  char buffer[1024];
  char *buffer_ptr = buffer;
  buffer_ptr += sprintf(buffer_ptr, "#!/bin/bash\n");
  buffer_ptr +=
      sprintf(buffer_ptr,
              "if [ \"$APPASERVER_DATABASE\" != \"\" ]\n"
              "then\n"
              "	application=$APPASERVER_DATABASE\n"
              "elif [ \"$DATABASE\" != \"\" ]\n"
              "then\n"
              "	application=$DATABASE\n"
              "fi\n"
              "\n"
              "if [ \"$application\" = \"\" ]\n"
              "then\n"
              "	echo \"Error in `basename.e $0 n`: you must first:\" 1>&2\n"
              "	echo \"$ . set_database\" 1>&2\n"
              "	exit 1\n"
              "fi\n");
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<environ_get_shell_snippet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    -0x400(%rbp),%rax
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x408(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x408(%rbp)
mov    -0x408(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x408(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x408(%rbp)
lea    -0x400(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<environ_get_shell_snippet>:
sub    $0x408,%rsp
movabs $0xa687361622f6e,%rax
mov    %rax,0x5(%rsp)
movabs $0x622f6e69622f2123,%rax
6e 2f 62
mov    %rax,(%rsp)
lea    0xc(%rsp),%rdi
lea    0xebd(%rip),%rsi
mov    $0x109,%edx
call   1030 <memcpy@plt>
mov    %rsp,%rdi
call   1040 <strdup@plt>
add    $0x408,%rsp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"#!/bin/bash\0A\00"
@.str.1 = [265 x i8] c"if [ \22$APPASERVER_DATABASE\22 != \22\22 ]\0Athen\0A\09application=$APPASERVER_DATABASE\0Aelif [ \22$DATABASE\22 != \22\22 ]\0Athen\0A\09application=$DATABASE\0Afi\0A\0Aif [ \22$application\22 = \22\22 ]\0Athen\0A\09echo \22Error in `basename.e $0 n`: you must first:\22 1>&2\0A\09echo \22$ . set_database\22 1>&2\0A\09exit 1\0Afi\0A\00"
define i8* @environ_get_shell_snippet() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = sext i32 %5 to i64
%8 = getelementptr inbounds i8, i8* %6, i64 %7
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([265 x i8], [265 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
store i8* %13, i8** %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%15 = call i8* @strdup(i8* %14)
ret i8* %15
}

LLVM IR (-O2):
@.str = [13 x i8] c"#!/bin/bash\0A\00"
@.str.1 = [265 x i8] c"if [ \22$APPASERVER_DATABASE\22 != \22\22 ]\0Athen\0A\09application=$APPASERVER_DATABASE\0Aelif [ \22$DATABASE\22 != \22\22 ]\0Athen\0A\09application=$DATABASE\0Afi\0A\0Aif [ \22$application\22 = \22\22 ]\0Athen\0A\09echo \22Error in `basename.e $0 n`: you must first:\22 1>&2\0A\09echo \22$ . set_database\22 1>&2\0A\09exit 1\0Afi\0A\00"
define noalias i8* @environ_get_shell_snippet() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 12
%4 = call i8* @strdup(i8* %2)
ret i8* %4
}