#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *ftsi_bc_hash(char *, char *);
char *ftsi_generate_bc_salt(int /*<<< orphan*/ *, int);
int print_usage();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int strtol(char *, int /*<<< orphan*/ *, int);
int hash(char **args) {
  if (args[1] == NULL) {
    fprintf(stderr, "\n** missing password to hash **\n\n");
    return print_usage();
  }
  int work_factor = 9;
  if (args[2])
    work_factor = strtol(args[2], NULL, 10);
  char *salt = ftsi_generate_bc_salt(NULL, work_factor);
  if (salt == NULL) {
    fprintf(stderr, "\n** failed to generate salt **\n\n");
    return 2;
  }
  printf("%s\n", ftsi_bc_hash(args[1], salt));
  return 0;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    119f <hash+0x3f>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1070 <print_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1231 <hash+0xd1>
movl   $0x9,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     11ce <hash+0x6e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <ftsi_generate_bc_salt@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120a <hash+0xaa>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1231 <hash+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <ftsi_bc_hash@plt>
mov    %rax,%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,0x8(%rdi)
je     1187 <hash+0x27>
mov    %rdi,%rbx
mov    0x10(%rdi),%rdi
test   %rdi,%rdi
je     11aa <hash+0x4a>
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%esi
jmp    11af <hash+0x4f>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <print_usage@plt>
mov    $0x9,%esi
xor    %r14d,%r14d
xor    %edi,%edi
call   1080 <ftsi_generate_bc_salt@plt>
test   %rax,%rax
je     11db <hash+0x7b>
mov    0x8(%rbx),%rdi
mov    %rax,%rsi
call   1030 <ftsi_bc_hash@plt>
lea    0xe72(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    11f6 <hash+0x96>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"\0A** missing password to hash **\0A\0A\00"
@.str.1 = [33 x i8] c"\0A** failed to generate salt **\0A\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @hash(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = getelementptr inbounds i8*, i8** %6, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (...) @print_usage()
store i32 %13, i32* %2
br label %39
14: ; preds = %1
store i32 9, i32* %4
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i32* null, i32 10)
store i32 %23, i32* %4
br label %24
24: ; preds = %19, %14
%25 = load i32, i32* %4
%26 = call i8* @ftsi_generate_bc_salt(i32* null, i32 %25)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %2
br label %39
32: ; preds = %24
%33 = load i8**, i8*** %3
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8*, i8** %5
%37 = call i8* @ftsi_bc_hash(i8* %35, i8* %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %32, %29, %10
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"\0A** missing password to hash **\0A\0A\00"
@.str.1 = [33 x i8] c"\0A** failed to generate salt **\0A\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @hash(i8** nocapture %0) {
%2 = getelementptr inbounds i8*, i8** %0, i64 1
%3 = load i8*, i8** %2
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @print_usage()
br label %26
9: ; preds = %1
%10 = getelementptr inbounds i8*, i8** %0, i64 2
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 10)
br label %15
15: ; preds = %13, %9
%16 = phi i32 [ %14, %13 ], [ 9, %9 ]
%17 = tail call i8* @ftsi_generate_bc_salt(i32* null, i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %26
22: ; preds = %15
%23 = load i8*, i8** %2
%24 = tail call i8* @ftsi_bc_hash(i8* %23, i8* %17)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %19, %22, %5
%27 = phi i32 [ %8, %5 ], [ 2, %19 ], [ 0, %22 ]
ret i32 %27
}