#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 passwd {
  char *pw_dir;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
struct passwd *getpwnam(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
char *str2md5(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
char *get_Authorization(char *filename, char *username, char **m5sum) {
  char *auth_buf = NULL;
  int fd;
  char buf[1024];
  struct passwd *ppass;
  if ((auth_buf = (char *)malloc(1024)) == NULL) {
    fprintf(stderr, "get_Authorization: Cannot Malloc auth buffer\n");
    exit(1);
  } else {
    memset(auth_buf, '\0', 1024);
  }
  if ((ppass = getpwnam(username)) == NULL) {
    fprintf(stderr, "get_Authorization: Cannot get user:%s passwd parameters\n",
            username);
    free(auth_buf);
    return (NULL);
  }
  snprintf(buf, sizeof(buf), "%s/.suites/%s", ppass->pw_dir, filename);
  if (access(buf, R_OK) != 0) {
    fprintf(stderr, "get_Authorization:  Parameters file:%s does not exist \n",
            buf);
    free(auth_buf);
    return (NULL);
  }
  if ((fd = open(buf, O_RDONLY)) == -1) {
    fprintf(stderr, "get_Authorization: Can't open Parameters file:%s\n",
            filename);
    free(auth_buf);
    return (NULL);
  }
  if (read(fd, auth_buf, 1024) <= 0) {
    fprintf(stderr, "get_Authorization: Can't read Parameters file\n");
    close(fd);
    free(auth_buf);
    return (NULL);
  }
  close(fd);
  *m5sum = str2md5(auth_buf, strlen(auth_buf));
  return (auth_buf);
}


x86 assembly (clang, -O0):
<get_Authorization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x400,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1228 <get_Authorization+0x58>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <getpwnam@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
jne    1283 <get_Authorization+0xb3>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13da <get_Authorization+0x20a>
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%r8
mov    $0x400,%esi
lea    0xdc3(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x430(%rbp),%rdi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
je     12fc <get_Authorization+0x12c>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13da <get_Authorization+0x20a>
lea    -0x430(%rbp),%rdi
mov    0x2cde(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    134e <get_Authorization+0x17e>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13da <get_Authorization+0x20a>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
jg     139e <get_Authorization+0x1ce>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    13da <get_Authorization+0x20a>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    %eax,%esi
call   1080 <str2md5@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_Authorization>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x400,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     1329 <get_Authorization+0x159>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   10a0 <getpwnam@plt>
test   %rax,%rax
je     1264 <get_Authorization+0x94>
mov    (%rax),%rcx
lea    0xe44(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10e0 <access@plt>
test   %rax,%rax
je     129b <get_Authorization+0xcb>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
xor    %r14d,%r14d
mov    %rsp,%rdx
jmp    127a <get_Authorization+0xaa>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
xor    %r14d,%r14d
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     12e8 <get_Authorization+0x118>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %rax,%rax
jle    1303 <get_Authorization+0x133>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1080 <str2md5@plt>
mov    %rax,(%r14)
mov    %r12,%r14
jmp    1289 <get_Authorization+0xb9>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
xor    %r14d,%r14d
mov    %r15,%rdx
jmp    127a <get_Authorization+0xaa>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
jmp    1281 <get_Authorization+0xb1>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [46 x i8] c"get_Authorization: Cannot Malloc auth buffer\0A\00"
@.str.1 = [57 x i8] c"get_Authorization: Cannot get user:%s passwd parameters\0A\00"
@.str.2 = [14 x i8] c"%s/.suites/%s\00"
@R_OK = global i32 0
@.str.3 = [56 x i8] c"get_Authorization: Parameters file:%s does not exist \0A\00"
@O_RDONLY = global i32 0
@.str.4 = [50 x i8] c"get_Authorization: Can't open Parameters file:%s\0A\00"
@.str.5 = [47 x i8] c"get_Authorization: Can't read Parameters file\0A\00"
define i8* @get_Authorization(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca %struct.passwd*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i8* null, i8** %8
%12 = call i64 @malloc(i32 1024)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8*, i8** %8
%21 = call i32 @memset(i8* %20, i8 signext 0, i32 1024)
br label %22
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = call %struct.passwd* @getpwnam(i8* %23)
store %struct.passwd* %24, %struct.passwd** %11
%25 = icmp eq %struct.passwd* %24, null
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %8
%31 = call i32 @free(i8* %30)
store i8* null, i8** %4
br label %81
32: ; preds = %22
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%34 = load %struct.passwd*, %struct.passwd** %11
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = load i8*, i8** %5
%38 = call i32 @snprintf(i8* %33, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %37)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* @R_OK
%41 = call i64 @access(i8* %39, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %32
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
store i8* null, i8** %4
br label %81
49: ; preds = %32
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* @O_RDONLY
%52 = call i32 @open(i8* %50, i32 %51)
store i32 %52, i32* %9
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %5
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
store i8* null, i8** %4
br label %81
60: ; preds = %49
%61 = load i32, i32* %9
%62 = load i8*, i8** %8
%63 = call i64 @read(i32 %61, i8* %62, i32 1024)
%64 = icmp sle i64 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%68 = load i32, i32* %9
%69 = call i32 @close(i32 %68)
%70 = load i8*, i8** %8
%71 = call i32 @free(i8* %70)
store i8* null, i8** %4
br label %81
72: ; preds = %60
%73 = load i32, i32* %9
%74 = call i32 @close(i32 %73)
%75 = load i8*, i8** %8
%76 = load i8*, i8** %8
%77 = call i32 @strlen(i8* %76)
%78 = call i8* @str2md5(i8* %75, i32 %77)
%79 = load i8**, i8*** %7
store i8* %78, i8** %79
%80 = load i8*, i8** %8
store i8* %80, i8** %4
br label %81
81: ; preds = %72, %65, %54, %43, %26
%82 = load i8*, i8** %4
ret i8* %82
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [46 x i8] c"get_Authorization: Cannot Malloc auth buffer\0A\00"
@.str.1 = [57 x i8] c"get_Authorization: Cannot get user:%s passwd parameters\0A\00"
@.str.2 = [14 x i8] c"%s/.suites/%s\00"
@R_OK = global i32 0
@.str.3 = [56 x i8] c"get_Authorization: Parameters file:%s does not exist \0A\00"
@O_RDONLY = global i32 0
@.str.4 = [50 x i8] c"get_Authorization: Can't open Parameters file:%s\0A\00"
@.str.5 = [47 x i8] c"get_Authorization: Can't read Parameters file\0A\00"
define i8* @get_Authorization(i8* %0, i8* %1, i8** nocapture writeonly %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @malloc(i32 1024)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = tail call i32 @memset(i8* %7, i8 signext 0, i32 1024)
%15 = tail call %struct.passwd* @getpwnam(i8* %1)
%16 = icmp eq %struct.passwd* %15, null
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%20 = tail call i32 @free(i8* %7)
br label %52
21: ; preds = %13
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %0)
%25 = load i32, i32* @R_OK
%26 = call i64 @access(i8* %5, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %21
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%31 = call i32 @free(i8* %7)
br label %52
32: ; preds = %21
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* %5, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%39 = call i32 @free(i8* %7)
br label %52
40: ; preds = %32
%41 = call i64 @read(i32 %34, i8* %7, i32 1024)
%42 = icmp slt i64 %41, 1
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @close(i32 %34)
%47 = call i32 @free(i8* %7)
br label %52
48: ; preds = %40
%49 = call i32 @close(i32 %34)
%50 = call i32 @strlen(i8* %7)
%51 = call i8* @str2md5(i8* %7, i32 %50)
store i8* %51, i8** %2
br label %52
52: ; preds = %48, %43, %36, %28, %17
%53 = phi i8* [ null, %17 ], [ null, %28 ], [ null, %36 ], [ null, %43 ], [ %7, %48 ]
ret i8* %53
}