#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*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned int *);
int strlen(char const *);
int md5_str2num(unsigned char *md5num, const char *md5str) {
  int i;
  char buff[4] = {0};
  unsigned int n;
  memset(md5num, 0, 16);
  if (strlen(md5str) != 32)
    return -1;
  for (i = 0; i < 16; i++) {
    buff[0] = md5str[i * 2];
    buff[1] = md5str[i * 2 + 1];
    sscanf(buff, "%x", &n);
    md5num[i] = n;
  }
  return 0;
}


x86 assembly (clang, -O0):
<md5_str2num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x20,%eax
je     117e <md5_str2num+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <md5_str2num+0xc1>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11ea <md5_str2num+0xba>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1f(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <md5_str2num+0x55>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5_str2num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,(%rsp)
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ecx
cmp    $0x20,%eax
jne    11b5 <md5_str2num+0x85>
lea    0xe93(%rip),%r12
mov    %rsp,%r13
lea    0x4(%rsp),%rbp
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%r15,2),%eax
mov    %al,(%rsp)
movzbl 0x1(%rbx,%r15,2),%eax
mov    %al,0x1(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%r14,%r15,1)
add    $0x1,%r15
cmp    $0x10,%r15
jne    1180 <md5_str2num+0x50>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
define i32 @md5_str2num(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = bitcast [4 x i8]* %7 to i8*
%10 = load i8*, i8** %4
%11 = call i32 @memset(i8* %10, i32 0, i32 16)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp ne i32 %13, 32
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %48
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %44, %16
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 16
br i1 %19, label %20, label %47
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = mul nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
store i8 %26, i8* %27
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = mul nsw i32 %29, 2
%31 = add nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
%34 = load i8, i8* %33
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 1
store i8 %34, i8* %35
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%37 = call i32 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%38 = load i32, i32* %8
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %20
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %17
47: ; preds = %17
store i32 0, i32* %3
br label %48
48: ; preds = %47, %15
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define i32 @md5_str2num(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @memset(i8* %0, i32 0, i32 16)
%8 = tail call i32 @strlen(i8* %1)
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = bitcast i32* %3 to [4 x i8]*
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 1
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %25, %13 ]
%15 = shl nuw nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = or i64 %15, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %12
%21 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%22 = load i32, i32* %4
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %23, i8* %24
%25 = add nuw nsw i64 %14, 1
%26 = icmp eq i64 %25, 16
br i1 %26, label %27, label %13
27: ; preds = %13, %2
%28 = phi i32 [ -1, %2 ], [ 0, %13 ]
ret i32 %28
}