#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 *__md5_crypt_r(char const *, char const *, char *, int);
char *realloc(char *, int);
int strlen(char const *);
char *__md5_crypt(const char *key, const char *salt) {
  static char *buffer = NULL;
  static int buflen = 0;
  int needed = 3 + strlen(salt) + 1 + 26 + 1;
  if (buflen < needed) {
    buflen = needed;
    if ((buffer = realloc(buffer, buflen)) == NULL)
      return NULL;
  }
  return __md5_crypt_r(key, salt, buffer, buflen);
}


x86 assembly (clang, -O0):
<__md5_crypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x3,%eax
add    $0x1,%eax
add    $0x1a,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2eea(%rip),%eax
cmp    -0x1c(%rbp),%eax
jge    11a5 <__md5_crypt+0x75>
mov    -0x1c(%rbp),%eax
mov    %eax,0x2ed8(%rip)
mov    0x2ec9(%rip),%rdi
mov    0x2ecb(%rip),%esi
call   1050 <realloc@plt>
mov    %rax,0x2eb7(%rip)
cmp    $0x0,%rax
jne    11a0 <__md5_crypt+0x70>
movq   $0x0,-0x8(%rbp)
jmp    11c3 <__md5_crypt+0x93>
jmp    11a5 <__md5_crypt+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e8c(%rip),%rdx
mov    0x2e8e(%rip),%ecx
call   1030 <__md5_crypt_r@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__md5_crypt>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1f,%eax
mov    0x2efd(%rip),%ecx
cmp    %eax,%ecx
jge    117a <__md5_crypt+0x4a>
mov    %eax,0x2ef3(%rip)
mov    0x2ee4(%rip),%rdi
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,0x2ed6(%rip)
test   %rax,%rax
je     1193 <__md5_crypt+0x63>
mov    %rax,%rdx
mov    0x2ed0(%rip),%ecx
jmp    1181 <__md5_crypt+0x51>
mov    0x2ebf(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <__md5_crypt_r@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__md5_crypt.buffer = internal global i8* null
@__md5_crypt.buflen = internal global i32 0
define i8* @__md5_crypt(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 3, %8
%10 = add nsw i32 %9, 1
%11 = add nsw i32 %10, 26
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
%13 = load i32, i32* @__md5_crypt.buflen
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* %6
store i32 %17, i32* @__md5_crypt.buflen
%18 = load i8*, i8** @__md5_crypt.buffer
%19 = load i32, i32* @__md5_crypt.buflen
%20 = call i8* @realloc(i8* %18, i32 %19)
store i8* %20, i8** @__md5_crypt.buffer
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %16
store i8* null, i8** %3
br label %30
23: ; preds = %16
br label %24
24: ; preds = %23, %2
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = load i8*, i8** @__md5_crypt.buffer
%28 = load i32, i32* @__md5_crypt.buflen
%29 = call i8* @__md5_crypt_r(i8* %25, i8* %26, i8* %27, i32 %28)
store i8* %29, i8** %3
br label %30
30: ; preds = %24, %22
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@__md5_crypt.buffer = internal unnamed_addr global i8* null
@__md5_crypt.buflen = internal unnamed_addr global i32 0
define i8* @__md5_crypt(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 31
%5 = load i32, i32* @__md5_crypt.buflen
%6 = icmp slt i32 %5, %4
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = load i8*, i8** @__md5_crypt.buffer
br label %15
9: ; preds = %2
store i32 %4, i32* @__md5_crypt.buflen
%10 = load i8*, i8** @__md5_crypt.buffer
%11 = tail call i8* @realloc(i8* %10, i32 %4)
store i8* %11, i8** @__md5_crypt.buffer
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = load i32, i32* @__md5_crypt.buflen
br label %15
15: ; preds = %13, %7
%16 = phi i32 [ %5, %7 ], [ %14, %13 ]
%17 = phi i8* [ %8, %7 ], [ %11, %13 ]
%18 = tail call i8* @__md5_crypt_r(i8* %0, i8* %1, i8* %17, i32 %16)
br label %19
19: ; preds = %9, %15
%20 = phi i8* [ %18, %15 ], [ null, %9 ]
ret i8* %20
}