#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 */
scalar_t__ O_CREAT;
scalar_t__ O_WRONLY;
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(struct passwd *);
struct passwd *getpwnam(char *);
int open(char *, scalar_t__, int);
int snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
char *str2md5(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int);
void set_Authorization(unsigned int pid, char *hostn, char *hip, int port,
                       char *filename, char *username, char **m5sum) {
  int fd;
  char buf[1024];
  int nc, rt;
  struct passwd *ppass;
  if ((ppass = getpwnam(username)) == NULL) {
    fprintf(stderr, "set_Authorization: Cannot get user:%s passwd parameters\n",
            username);
    return;
  }
  snprintf(buf, sizeof(buf), "%s/.suites/%s", ppass->pw_dir, filename);
  if ((fd = open(buf, O_WRONLY + O_CREAT, 0600)) == -1) {
    fprintf(stderr, "set_Authorization: Can't open Parameters file:%s\n",
            filename);
    free(ppass);
    exit(1);
  }
  nc = snprintf(buf, sizeof(buf), "seqpid=%u seqhost=%s seqip=%s seqport=%d\n",
                pid, hostn, hip, port);
  rt = write(fd, buf, nc);
  rt = close(fd);
  *m5sum = str2md5(buf, strlen(buf));
}


x86 assembly (clang, -O0):
<set_Authorization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <getpwnam@plt>
mov    %rax,-0x450(%rbp)
cmp    $0x0,%rax
jne    11fd <set_Authorization+0x5d>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe0d(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1311 <set_Authorization+0x171>
lea    -0x440(%rbp),%rdi
mov    -0x450(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%r8
mov    $0x400,%esi
lea    0xe1b(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x440(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%rsi
mov    0x2dbb(%rip),%rax
add    (%rax),%rsi
mov    $0x180,%edx
call   10b0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    1285 <set_Authorization+0xe5>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x450(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x440(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x1c(%rbp),%eax
mov    $0x400,%esi
lea    0xdd3(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    %eax,-0x444(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x448(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x448(%rbp)
lea    -0x440(%rbp),%rax
mov    %rax,-0x458(%rbp)
lea    -0x440(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x458(%rbp),%rdi
mov    %eax,%esi
call   1080 <str2md5@plt>
mov    %rax,%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_Authorization>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %r9,%rbp
mov    %r8,%r13
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,0x28(%rsp)
mov    %edi,0x14(%rsp)
mov    0x470(%rsp),%rbx
mov    %r9,%rdi
call   1090 <getpwnam@plt>
test   %rax,%rax
je     12a8 <set_Authorization+0x108>
mov    %rax,%r12
mov    %r14,0x18(%rsp)
mov    %rbx,0x20(%rsp)
mov    (%rax),%rcx
lea    0xe43(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r13,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    0x2db4(%rip),%rax
mov    0x2ddd(%rip),%rcx
mov    (%rcx),%rsi
add    (%rax),%rsi
mov    %rbp,%rdi
mov    $0x180,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12d1 <set_Authorization+0x131>
mov    %eax,%r14d
mov    %r15d,(%rsp)
lea    0xe34(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    0x14(%rsp),%ecx
mov    0x28(%rsp),%r8
mov    0x18(%rsp),%r9
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <str2md5@plt>
mov    0x20(%rsp),%rcx
mov    %rax,(%rcx)
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd48(%rip),%rsi
mov    %rbp,%rdx
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <fprintf@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
mov    %r13,%rdx
call   10a0 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [57 x i8] c"set_Authorization: Cannot get user:%s passwd parameters\0A\00"
@.str.1 = [14 x i8] c"%s/.suites/%s\00"
@O_WRONLY = global i64 0
@O_CREAT = global i64 0
@.str.2 = [50 x i8] c"set_Authorization: Can't open Parameters file:%s\0A\00"
@.str.3 = [42 x i8] c"seqpid=%u seqhost=%s seqip=%s seqport=%d\0A\00"
define void @set_Authorization(i32 %0, i8* %1, i8* %2, i32 %3, i8* %4, i8* %5, i8** %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8**
%15 = alloca i32
%16 = alloca [1024 x i8]
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.passwd*
store i32 %0, i32* %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8** %6, i8*** %14
%20 = load i8*, i8** %13
%21 = call %struct.passwd* @getpwnam(i8* %20)
store %struct.passwd* %21, %struct.passwd** %19
%22 = icmp eq %struct.passwd* %21, null
br i1 %22, label %23, label %27
23: ; preds = %7
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %13
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %65
27: ; preds = %7
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%29 = load %struct.passwd*, %struct.passwd** %19
%30 = getelementptr inbounds %struct.passwd, %struct.passwd* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = load i8*, i8** %12
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%35 = load i64, i64* @O_WRONLY
%36 = load i64, i64* @O_CREAT
%37 = add nsw i64 %35, %36
%38 = call i32 @open(i8* %34, i64 %37, i32 384)
store i32 %38, i32* %15
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %47
40: ; preds = %27
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %12
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load %struct.passwd*, %struct.passwd** %19
%45 = call i32 @free(%struct.passwd* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %27
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%49 = load i32, i32* %8
%50 = load i8*, i8** %9
%51 = load i8*, i8** %10
%52 = load i32, i32* %11
%53 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %48, i32 1024, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %49, i8* %50, i8* %51, i32 %52)
store i32 %53, i32* %17
%54 = load i32, i32* %15
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%56 = load i32, i32* %17
%57 = call i32 @write(i32 %54, i8* %55, i32 %56)
store i32 %57, i32* %18
%58 = load i32, i32* %15
%59 = call i32 @close(i32 %58)
store i32 %59, i32* %18
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = call i8* @str2md5(i8* %60, i32 %62)
%64 = load i8**, i8*** %14
store i8* %63, i8** %64
br label %65
65: ; preds = %47, %23
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@stderr = global i32 0
@.str = [57 x i8] c"set_Authorization: Cannot get user:%s passwd parameters\0A\00"
@.str.1 = [14 x i8] c"%s/.suites/%s\00"
@O_WRONLY = global i64 0
@O_CREAT = global i64 0
@.str.2 = [50 x i8] c"set_Authorization: Can't open Parameters file:%s\0A\00"
@.str.3 = [42 x i8] c"seqpid=%u seqhost=%s seqip=%s seqport=%d\0A\00"
define void @set_Authorization(i32 %0, i8* %1, i8* %2, i32 %3, i8* %4, i8* %5, i8** nocapture writeonly %6) {
%8 = alloca [1024 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%10 = tail call %struct.passwd* @getpwnam(i8* %5)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %35
15: ; preds = %7
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %4)
%19 = load i64, i64* @O_WRONLY
%20 = load i64, i64* @O_CREAT
%21 = add nsw i64 %20, %19
%22 = call i32 @open(i8* %9, i64 %21, i32 384)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%27 = call i32 @free(%struct.passwd* %10)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* %1, i8* %2, i32 %3)
%31 = call i32 @write(i32 %22, i8* %9, i32 %30)
%32 = call i32 @close(i32 %22)
%33 = call i32 @strlen(i8* %9)
%34 = call i8* @str2md5(i8* %9, i32 %33)
store i8* %34, i8** %6
br label %35
35: ; preds = %29, %12
ret void
}