#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 */
typedef unsigned int uint8_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int sscanf(char const *, char *, unsigned int *);
uint8_t *parse_hash(const char *input) {
  uint8_t *r = (uint8_t *)malloc(sizeof(uint8_t) * 32);
  for (int i = 0; i < 32; i++) {
    unsigned tmp;
    if (sscanf(input + 2 * i, "%02x", &tmp) != 1) {
      printf("hash parsing error\n");
      return NULL;
    }
    r[i] = tmp & 0xff;
  }
  return r;
}


x86 assembly (clang, -O0):
<parse_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x80,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    11be <parse_hash+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xe8f(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     119c <parse_hash+0x6c>
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <parse_hash+0x96>
mov    -0x20(%rbp),%edx
and    $0xff,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <parse_hash+0x21>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hash>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x80,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xeaa(%rip),%r15
lea    0xc(%rsp),%r12
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    118a <parse_hash+0x5a>
movzbl 0xc(%rsp),%eax
mov    %eax,0x0(%r13,%rbx,2)
add    $0x2,%rbx
cmp    $0x40,%rbx
jne    1160 <parse_hash+0x30>
jmp    1199 <parse_hash+0x69>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [20 x i8] c"hash parsing error\0A\00"
define i32* @parse_hash(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i64 @malloc(i32 128)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %4
store i32 0, i32* %5
br label %9
9: ; preds = %29, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = mul nsw i32 2, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %2
br label %34
22: ; preds = %12
%23 = load i32, i32* %6
%24 = and i32 %23, 255
%25 = load i32*, i32** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %9
32: ; preds = %9
%33 = load i32*, i32** %4
store i32* %33, i32** %2
br label %34
34: ; preds = %32, %20
%35 = load i32*, i32** %2
ret i32* %35
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@str = [19 x i8] c"hash parsing error\00"
define i32* @parse_hash(i8* nocapture %0) {
%2 = alloca i32
%3 = tail call i64 @malloc(i32 128)
%4 = inttoptr i64 %3 to i32*
%5 = bitcast i32* %2 to i8*
br label %6
6: ; preds = %1, %14
%7 = phi i64 [ 0, %1 ], [ %18, %14 ]
%8 = shl nuw nsw i64 %7, 1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %20
14: ; preds = %6
%15 = load i32, i32* %2
%16 = and i32 %15, 255
%17 = getelementptr inbounds i32, i32* %4, i64 %7
store i32 %16, i32* %17
%18 = add nuw nsw i64 %7, 1
%19 = icmp eq i64 %18, 32
br i1 %19, label %20, label %6
20: ; preds = %14, %12
%21 = phi i32* [ null, %12 ], [ %4, %14 ]
ret i32* %21
}