#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 changepass_cert(char const *, char *, size_t);
int changepass_crypt(char const *, char *, size_t);
int changepass_md5(char const *, char *, size_t);
int changepass_pam(char const *, char const *, char *, size_t);
int changepass_sha(char const *, char *, size_t);
int strlen(char *);
scalar_t__ strncmp(char const *, char *, int);
int changepass(const char *user, const char *pass, char *buffer, size_t len) {
  if (!user)
    return -1;
  if (strncmp(pass, "$1$", strlen("$1$")) == 0)
    return changepass_md5(pass + strlen("$1$"), buffer, len);
  if (strncmp(pass, "{SHA}", strlen("{SHA}")) == 0)
    return changepass_sha(pass + strlen("{SHA}"), buffer, len);
  if (strncmp(pass, "{pam}", strlen("{pam}")) == 0)
    return changepass_pam(user, pass + strlen("{pam}"), buffer, len);
  if (strncmp(pass, "{cert}", strlen("{cert}")) == 0)
    return changepass_cert(pass + strlen("{cert}"), buffer, len);
  return changepass_crypt(pass, buffer, len);
  return -1;
}


x86 assembly (clang, -O0):
<changepass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119f <changepass+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1347 <changepass+0x1d7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe52(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe40(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1201 <changepass+0x91>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe22(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <changepass_md5@plt>
mov    %eax,-0x4(%rbp)
jmp    1347 <changepass+0x1d7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdf4(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xde2(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1263 <changepass+0xf3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xdc4(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <changepass_sha@plt>
mov    %eax,-0x4(%rbp)
jmp    1347 <changepass+0x1d7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xd98(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xd86(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12d1 <changepass+0x161>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xd60(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
cltq
add    %rax,%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1090 <changepass_pam@plt>
mov    %eax,-0x4(%rbp)
jmp    1347 <changepass+0x1d7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    0xd30(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
lea    0xd1e(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1333 <changepass+0x1c3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    0xd00(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <changepass_cert@plt>
mov    %eax,-0x4(%rbp)
jmp    1347 <changepass+0x1d7>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <changepass_crypt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changepass>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1239 <changepass+0xc9>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
lea    0xe6b(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1248 <changepass+0xd8>
lea    0xe4a(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1270 <changepass+0x100>
lea    0xe2b(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1298 <changepass+0x128>
lea    0xe0c(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12c3 <changepass+0x153>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1080 <changepass_crypt@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdb1(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <changepass_md5@plt>
lea    0xd8d(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <changepass_sha@plt>
lea    0xd6b(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1090 <changepass_pam@plt>
lea    0xd46(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r13
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <changepass_cert@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [6 x i8] c"{SHA}\00"
@.str.2 = [6 x i8] c"{pam}\00"
@.str.3 = [7 x i8] c"{cert}\00"
define i32 @changepass(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %4
store i32 -1, i32* %5
br label %71
13: ; preds = %4
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%16 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8*, i8** %8
%24 = load i64, i64* %9
%25 = call i32 @changepass_md5(i8* %22, i8* %23, i64 %24)
store i32 %25, i32* %5
br label %71
26: ; preds = %13
%27 = load i8*, i8** %7
%28 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%29 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8*, i8** %8
%37 = load i64, i64* %9
%38 = call i32 @changepass_sha(i8* %35, i8* %36, i64 %37)
store i32 %38, i32* %5
br label %71
39: ; preds = %26
%40 = load i8*, i8** %7
%41 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%42 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = load i8*, i8** %6
%46 = load i8*, i8** %7
%47 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8*, i8** %8
%51 = load i64, i64* %9
%52 = call i32 @changepass_pam(i8* %45, i8* %49, i8* %50, i64 %51)
store i32 %52, i32* %5
br label %71
53: ; preds = %39
%54 = load i8*, i8** %7
%55 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%56 = call i64 @strncmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %53
%59 = load i8*, i8** %7
%60 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8*, i8** %8
%64 = load i64, i64* %9
%65 = call i32 @changepass_cert(i8* %62, i8* %63, i64 %64)
store i32 %65, i32* %5
br label %71
66: ; preds = %53
%67 = load i8*, i8** %7
%68 = load i8*, i8** %8
%69 = load i64, i64* %9
%70 = call i32 @changepass_crypt(i8* %67, i8* %68, i64 %69)
store i32 %70, i32* %5
br label %71
71: ; preds = %66, %58, %44, %31, %18, %12
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
@.str = [4 x i8] c"$1$\00"
@.str.1 = [6 x i8] c"{SHA}\00"
@.str.2 = [6 x i8] c"{pam}\00"
@.str.3 = [7 x i8] c"{cert}\00"
define i32 @changepass(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %44, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = tail call i32 @changepass_md5(i8* %13, i8* %2, i64 %3)
br label %44
15: ; preds = %6
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = tail call i32 @changepass_sha(i8* %22, i8* %2, i64 %3)
br label %44
24: ; preds = %15
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %1, i64 %30
%32 = tail call i32 @changepass_pam(i8* %0, i8* %31, i8* %2, i64 %3)
br label %44
33: ; preds = %24
%34 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%35 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %1, i64 %39
%41 = tail call i32 @changepass_cert(i8* %40, i8* %2, i64 %3)
br label %44
42: ; preds = %33
%43 = tail call i32 @changepass_crypt(i8* %1, i8* %2, i64 %3)
br label %44
44: ; preds = %4, %42, %37, %28, %19, %10
%45 = phi i32 [ %14, %10 ], [ %23, %19 ], [ %32, %28 ], [ %41, %37 ], [ %43, %42 ], [ -1, %4 ]
ret i32 %45
}