#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 */
char *SN_sha1;
char *SN_sha256;
char *SN_sha384;
char *SN_sha512;
scalar_t__ strncmp(char *, char const *, int);
int ipapwd_hash_type_to_alg(const char *hash_type, char **hash_alg_sn) {
  if (strncmp("{SSHA}", hash_type, 6) == 0) {
    *hash_alg_sn = SN_sha1;
    return 0;
  }
  if (strncmp("{SHA256}", hash_type, 8) == 0) {
    *hash_alg_sn = SN_sha256;
    return 0;
  }
  if (strncmp("{SHA384}", hash_type, 8) == 0) {
    *hash_alg_sn = SN_sha384;
    return 0;
  }
  if (strncmp("{SHA512}", hash_type, 8) == 0) {
    *hash_alg_sn = SN_sha512;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<ipapwd_hash_type_to_alg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed5(%rip),%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    115c <ipapwd_hash_type_to_alg+0x4c>
mov    0x2e82(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1217 <ipapwd_hash_type_to_alg+0x107>
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1198 <ipapwd_hash_type_to_alg+0x88>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1217 <ipapwd_hash_type_to_alg+0x107>
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d4 <ipapwd_hash_type_to_alg+0xc4>
mov    0x2e32(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1217 <ipapwd_hash_type_to_alg+0x107>
mov    -0x10(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1210 <ipapwd_hash_type_to_alg+0x100>
mov    0x2de6(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1217 <ipapwd_hash_type_to_alg+0x107>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipapwd_hash_type_to_alg>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     118f <ipapwd_hash_type_to_alg+0x7f>
lea    0xecd(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1198 <ipapwd_hash_type_to_alg+0x88>
lea    0xebd(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11a1 <ipapwd_hash_type_to_alg+0x91>
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11b0 <ipapwd_hash_type_to_alg+0xa0>
mov    0x2e53(%rip),%rax
jmp    11a8 <ipapwd_hash_type_to_alg+0x98>
mov    0x2e32(%rip),%rax
jmp    11a8 <ipapwd_hash_type_to_alg+0x98>
mov    0x2e31(%rip),%rax
jmp    11a8 <ipapwd_hash_type_to_alg+0x98>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"{SSHA}\00"
@SN_sha1 = global i8* null
@.str.1 = [9 x i8] c"{SHA256}\00"
@SN_sha256 = global i8* null
@.str.2 = [9 x i8] c"{SHA384}\00"
@SN_sha384 = global i8* null
@.str.3 = [9 x i8] c"{SHA512}\00"
@SN_sha512 = global i8* null
define i32 @ipapwd_hash_type_to_alg(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
store i8* %0, i8** %4
store i8** %1, i8*** %5
%6 = load i8*, i8** %4
%7 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6, i32 6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** @SN_sha1
%11 = load i8**, i8*** %5
store i8* %10, i8** %11
store i32 0, i32* %3
br label %34
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** @SN_sha256
%18 = load i8**, i8*** %5
store i8* %17, i8** %18
store i32 0, i32* %3
br label %34
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32 8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i8*, i8** @SN_sha384
%25 = load i8**, i8*** %5
store i8* %24, i8** %25
store i32 0, i32* %3
br label %34
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %27, i32 8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** @SN_sha512
%32 = load i8**, i8*** %5
store i8* %31, i8** %32
store i32 0, i32* %3
br label %34
33: ; preds = %26
store i32 -1, i32* %3
br label %34
34: ; preds = %33, %30, %23, %16, %9
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [7 x i8] c"{SSHA}\00"
@SN_sha1 = global i8* null
@.str.1 = [9 x i8] c"{SHA256}\00"
@SN_sha256 = global i8* null
@.str.2 = [9 x i8] c"{SHA384}\00"
@SN_sha384 = global i8* null
@.str.3 = [9 x i8] c"{SHA512}\00"
@SN_sha512 = global i8* null
define i32 @ipapwd_hash_type_to_alg(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i32 6)
%4 = icmp eq i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 8)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i64 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11, %8, %5, %2
%15 = phi i8** [ @SN_sha1, %2 ], [ @SN_sha256, %5 ], [ @SN_sha384, %8 ], [ @SN_sha512, %11 ]
%16 = load i8*, i8** %15
store i8* %16, i8** %1
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ -1, %11 ], [ 0, %14 ]
ret i32 %18
}