#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *parse_web_service_password(int /*<<< orphan*/ *);
int /*<<< orphan*/ simias_get_user_profile_dir_path(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int simias_get_web_service_credential(char *username, char *password) {
  char user_profile_dir[1024];
  char *user;
  char *pw;
  user = getenv("USER");
  if (!user)
    return -1;
  char simias_password_file_path[1024];
  FILE *simias_password_file;
  if (!simias_get_user_profile_dir_path(user_profile_dir)) {
    return -101;
  }
  do {
  } while (0);
  sprintf(simias_password_file_path, "%s%s.local.if", user_profile_dir, "/");
  do {
  } while (0);
  simias_password_file = fopen(simias_password_file_path, "r");
  if (!simias_password_file) {
    do {
    } while (0);
    return -107;
  }
  pw = parse_web_service_password(simias_password_file);
  fclose(simias_password_file);
  if (!(password)) {
    do {
    } while (0);
    return -1;
  }
  sprintf(password, "%s", pw);
  free(pw);
  sprintf(username, "%s", user);
  return 0;
}


x86 assembly (clang, -O0):
<simias_get_web_service_credential>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11b0 <simias_get_web_service_credential+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <simias_get_web_service_credential+0x156>
lea    -0x420(%rbp),%rdi
call   1040 <simias_get_user_profile_dir_path@plt>
cmp    $0x0,%eax
jne    11d1 <simias_get_web_service_credential+0x61>
movl   $0xffffff9b,-0x4(%rbp)
jmp    12c6 <simias_get_web_service_credential+0x156>
jmp    11d6 <simias_get_web_service_credential+0x66>
jmp    11db <simias_get_web_service_credential+0x6b>
lea    -0x830(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe15(%rip),%rsi
lea    0xe1c(%rip),%rcx
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    1203 <simias_get_web_service_credential+0x93>
lea    -0x830(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x838(%rbp)
cmpq   $0x0,-0x838(%rbp)
jne    1241 <simias_get_web_service_credential+0xd1>
jmp    1230 <simias_get_web_service_credential+0xc0>
jmp    1235 <simias_get_web_service_credential+0xc5>
movl   $0xffffff95,-0x4(%rbp)
jmp    12c6 <simias_get_web_service_credential+0x156>
mov    -0x838(%rbp),%rdi
call   1070 <parse_web_service_password@plt>
mov    %rax,-0x430(%rbp)
mov    -0x838(%rbp),%rdi
call   1060 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1281 <simias_get_web_service_credential+0x111>
jmp    1270 <simias_get_web_service_credential+0x100>
jmp    1275 <simias_get_web_service_credential+0x105>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <simias_get_web_service_credential+0x156>
mov    -0x18(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x430(%rbp),%rdi
call   1050 <free@plt>
mov    -0x10(%rbp),%rdi
mov    -0x428(%rbp),%rdx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simias_get_web_service_credential>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     122e <simias_get_web_service_credential+0xae>
mov    %rax,%r13
mov    %rsp,%rdi
call   1040 <simias_get_user_profile_dir_path@plt>
test   %eax,%eax
je     1235 <simias_get_web_service_credential+0xb5>
lea    0xe44(%rip),%rsi
lea    0xe4b(%rip),%rcx
lea    0x400(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0xe31(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123c <simias_get_web_service_credential+0xbc>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <parse_web_service_password@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1070 <fclose@plt>
test   %r15,%r15
je     122e <simias_get_web_service_credential+0xae>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <strcpy@plt>
mov    %r12,%rdi
call   1050 <free@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <strcpy@plt>
xor    %eax,%eax
jmp    1241 <simias_get_web_service_credential+0xc1>
mov    $0xffffffff,%eax
jmp    1241 <simias_get_web_service_credential+0xc1>
mov    $0xffffff9b,%eax
jmp    1241 <simias_get_web_service_credential+0xc1>
mov    $0xffffff95,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [14 x i8] c"%s%s.local.if\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @simias_get_web_service_credential(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %54
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = call i32 @simias_get_user_profile_dir_path(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 -101, i32* %3
br label %54
20: ; preds = %15
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %22
br label %27
27: ; preds = %26
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %10
%30 = load i32*, i32** %10
%31 = icmp ne i32* %30, null
br i1 %31, label %35, label %32
32: ; preds = %27
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
store i32 -107, i32* %3
br label %54
35: ; preds = %27
%36 = load i32*, i32** %10
%37 = call i8* @parse_web_service_password(i32* %36)
store i8* %37, i8** %8
%38 = load i32*, i32** %10
%39 = call i32 @fclose(i32* %38)
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %45, label %42
42: ; preds = %35
br label %43
43: ; preds = %42
br label %44
44: ; preds = %43
store i32 -1, i32* %3
br label %54
45: ; preds = %35
%46 = load i8*, i8** %5
%47 = load i8*, i8** %8
%48 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %4
%52 = load i8*, i8** %7
%53 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %45, %44, %34, %19, %14
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [14 x i8] c"%s%s.local.if\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [2 x i8] c"r\00"
define i32 @simias_get_web_service_credential(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = call i32 @simias_get_user_profile_dir_path(i8* %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = call i8* @parse_web_service_password(i32* %14)
%18 = call i32 @fclose(i32* %14)
%19 = icmp eq i8* %1, null
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = call i8* @strcpy(i8* %1, i8* dereferenceable(1) %17)
%22 = call i32 @free(i8* %17)
%23 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* %6)
br label %24
24: ; preds = %16, %12, %8, %20
%25 = phi i32 [ 0, %20 ], [ -101, %8 ], [ -107, %12 ], [ -1, %16 ]
br label %26
26: ; preds = %2, %24
%27 = phi i32 [ %25, %24 ], [ -1, %2 ]
ret i32 %27
}