#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*/ piece(char *, char, char *, int);
char *pipe2string(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *strdup(char *);
int session_load(char **login_name, char **last_access_date,
                 char **last_access_time, char **http_user_agent,
                 char *application_name, char *session_key) {
  char sys_string[1024];
  char piece_buffer[1024];
  char *input_record;
  char where[1024];
  char *select;
  sprintf(where, "appaserver_session = '%s'", session_key);
  select = "login_name,last_access_date,last_access_time,http_user_agent";
  sprintf(sys_string,
          "get_folder_data	application=\"%s\"		"
          "			folder=appaserver_sessions	"
          "			select=\"%s\"			"
          "			where=\"%s\"			",
          application_name, select, where);
  if (!(input_record = pipe2string(sys_string)))
    return 0;
  if (!*input_record)
    return 0;
  piece(piece_buffer, '^', input_record, 0);
  *login_name = strdup(piece_buffer);
  piece(piece_buffer, '^', input_record, 1);
  *last_access_date = strdup(piece_buffer);
  piece(piece_buffer, '^', input_record, 2);
  *last_access_time = strdup(piece_buffer);
  piece(piece_buffer, '^', input_record, 3);
  *http_user_agent = strdup(piece_buffer);
  return 1;
}


x86 assembly (clang, -O0):
<session_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0xc50(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0xe97(%rip),%rax
mov    %rax,-0xc58(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0xc58(%rbp),%rcx
lea    -0xc50(%rbp),%r8
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x440(%rbp),%rdi
call   1030 <pipe2string@plt>
mov    %rax,-0x848(%rbp)
cmp    $0x0,%rax
jne    11da <session_load+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    12c6 <session_load+0x186>
mov    -0x848(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11f6 <session_load+0xb6>
movl   $0x0,-0x4(%rbp)
jmp    12c6 <session_load+0x186>
lea    -0x840(%rbp),%rdi
mov    -0x848(%rbp),%rdx
mov    $0x5e,%esi
xor    %ecx,%ecx
call   1050 <piece@plt>
lea    -0x840(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x840(%rbp),%rdi
mov    -0x848(%rbp),%rdx
mov    $0x5e,%esi
mov    $0x1,%ecx
call   1050 <piece@plt>
lea    -0x840(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x840(%rbp),%rdi
mov    -0x848(%rbp),%rdx
mov    $0x5e,%esi
mov    $0x2,%ecx
call   1050 <piece@plt>
lea    -0x840(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x840(%rbp),%rdi
mov    -0x848(%rbp),%rdx
mov    $0x5e,%esi
mov    $0x3,%ecx
call   1050 <piece@plt>
lea    -0x840(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<session_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc18,%rsp
mov    %r8,%rbx
mov    %rcx,0x8(%rsp)
mov    %rdx,(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe96(%rip),%rsi
xor    %r15d,%r15d
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r9,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xed1(%rip),%rsi
lea    0xe8d(%rip),%rcx
lea    0x810(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <pipe2string@plt>
test   %rax,%rax
je     1258 <session_load+0x118>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1258 <session_load+0x118>
lea    0x410(%rsp),%r14
mov    %r14,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <piece@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,0x0(%r13)
mov    $0x1,%r15d
mov    %r14,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
mov    $0x1,%ecx
call   1050 <piece@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r12)
mov    %r14,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
mov    $0x2,%ecx
call   1050 <piece@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
mov    $0x5e,%esi
mov    %rbx,%rdx
mov    $0x3,%ecx
call   1050 <piece@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
mov    %r15d,%eax
add    $0xc18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"appaserver_session = '%s'\00"
@.str.1 = [61 x i8] c"login_name,last_access_date,last_access_time,http_user_agent\00"
@.str.2 = [98 x i8] c"get_folder_data\09application=\22%s\22\09\09\09\09\09folder=appaserver_sessions\09\09\09\09select=\22%s\22\09\09\09\09\09\09where=\22%s\22\09\09\09\00"
define i32 @session_load(i8** %0, i8** %1, i8** %2, i8** %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [1024 x i8]
%15 = alloca [1024 x i8]
%16 = alloca i8*
%17 = alloca [1024 x i8]
%18 = alloca i8*
store i8** %0, i8*** %8
store i8** %1, i8*** %9
store i8** %2, i8*** %10
store i8** %3, i8*** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%20 = load i8*, i8** %13
%21 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %20)
store i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8** %18
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%23 = load i8*, i8** %12
%24 = load i8*, i8** %18
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%26 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%28 = call i8* @pipe2string(i8* %27)
store i8* %28, i8** %16
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %6
store i32 0, i32* %7
br label %61
31: ; preds = %6
%32 = load i8*, i8** %16
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
store i32 0, i32* %7
br label %61
36: ; preds = %31
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%38 = load i8*, i8** %16
%39 = call i32 @piece(i8* %37, i8 signext 94, i8* %38, i32 0)
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%41 = call i8* @strdup(i8* %40)
%42 = load i8**, i8*** %8
store i8* %41, i8** %42
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%44 = load i8*, i8** %16
%45 = call i32 @piece(i8* %43, i8 signext 94, i8* %44, i32 1)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%47 = call i8* @strdup(i8* %46)
%48 = load i8**, i8*** %9
store i8* %47, i8** %48
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%50 = load i8*, i8** %16
%51 = call i32 @piece(i8* %49, i8 signext 94, i8* %50, i32 2)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%53 = call i8* @strdup(i8* %52)
%54 = load i8**, i8*** %10
store i8* %53, i8** %54
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%56 = load i8*, i8** %16
%57 = call i32 @piece(i8* %55, i8 signext 94, i8* %56, i32 3)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%59 = call i8* @strdup(i8* %58)
%60 = load i8**, i8*** %11
store i8* %59, i8** %60
store i32 1, i32* %7
br label %61
61: ; preds = %36, %35, %30
%62 = load i32, i32* %7
ret i32 %62
}

LLVM IR (-O2):
@.str = [26 x i8] c"appaserver_session = '%s'\00"
@.str.1 = [61 x i8] c"login_name,last_access_date,last_access_time,http_user_agent\00"
@.str.2 = [98 x i8] c"get_folder_data\09application=\22%s\22\09\09\09\09\09folder=appaserver_sessions\09\09\09\09select=\22%s\22\09\09\09\09\09\09where=\22%s\22\09\09\09\00"
define i32 @session_load(i8** nocapture writeonly %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3, i8* %4, i8* %5) {
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %5)
%14 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%15 = call i8* @pipe2string(i8* %10)
%16 = icmp eq i8* %15, null
br i1 %16, label %29, label %17
17: ; preds = %6
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %17
%21 = call i32 @piece(i8* %11, i8 signext 94, i8* %15, i32 0)
%22 = call i8* @strdup(i8* %11)
store i8* %22, i8** %0
%23 = call i32 @piece(i8* %11, i8 signext 94, i8* %15, i32 1)
%24 = call i8* @strdup(i8* %11)
store i8* %24, i8** %1
%25 = call i32 @piece(i8* %11, i8 signext 94, i8* %15, i32 2)
%26 = call i8* @strdup(i8* %11)
store i8* %26, i8** %2
%27 = call i32 @piece(i8* %11, i8 signext 94, i8* %15, i32 3)
%28 = call i8* @strdup(i8* %11)
store i8* %28, i8** %3
br label %29
29: ; preds = %17, %6, %20
%30 = phi i32 [ 1, %20 ], [ 0, %6 ], [ 0, %17 ]
ret i32 %30
}