#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 */
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sscanf(char const *, char *, unsigned int *);
int strlen(char const *);
void hexToInts(const char *hex, unsigned int **buffer, size_t *bytes) {
  if (buffer == NULL) {
    hex = "";
  }
  *bytes = strlen(hex) / 2;
  *buffer = (unsigned int *)malloc((*bytes) * sizeof(int));
  size_t i;
  for (i = 0; i < *bytes; i++) {
    sscanf(hex, "%2x", &((*buffer)[i]));
    hex += 2;
  }
}


x86 assembly (clang, -O0):
<hexToInts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <hexToInts+0x2a>
lea    0xead(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    11e7 <hexToInts+0xb7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe3b(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <hexToInts+0x67>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexToInts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
test   %rsi,%rsi
lea    0xeb8(%rip),%r13
cmovne %rdi,%r13
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rdi
mov    %rdi,(%r15)
shl    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
cmpq   $0x0,(%r15)
je     11d2 <hexToInts+0xa2>
lea    0xe81(%rip),%rsi
mov    %r13,%rdi
mov    %rax,%rdx
call   1050 <sscanf@plt>
cmpq   $0x2,(%r15)
jb     11d2 <hexToInts+0xa2>
add    $0x2,%r13
mov    $0x1,%ebx
mov    $0x4,%ebp
lea    0xe5b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14),%rdx
add    %rbp,%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <sscanf@plt>
add    $0x1,%rbx
add    $0x4,%rbp
add    $0x2,%r13
cmp    (%r15),%rbx
jb     11b0 <hexToInts+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"%2x\00"
define void @hexToInts(i8* %0, i32** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i64*
%7 = alloca i64
store i8* %0, i8** %4
store i32** %1, i32*** %5
store i64* %2, i64** %6
%8 = load i32**, i32*** %5
%9 = icmp eq i32** %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %11
11: ; preds = %10, %3
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = sdiv i32 %13, 2
%15 = sext i32 %14 to i64
%16 = load i64*, i64** %6
store i64 %15, i64* %16
%17 = load i64*, i64** %6
%18 = load i64, i64* %17
%19 = mul i64 %18, 4
%20 = call i64 @malloc(i64 %19)
%21 = inttoptr i64 %20 to i32*
%22 = load i32**, i32*** %5
store i32* %21, i32** %22
store i64 0, i64* %7
br label %23
23: ; preds = %37, %11
%24 = load i64, i64* %7
%25 = load i64*, i64** %6
%26 = load i64, i64* %25
%27 = icmp ult i64 %24, %26
br i1 %27, label %28, label %40
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = load i32**, i32*** %5
%31 = load i32*, i32** %30
%32 = load i64, i64* %7
%33 = getelementptr inbounds i32, i32* %31, i64 %32
%34 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %33)
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8* %36, i8** %4
br label %37
37: ; preds = %28
%38 = load i64, i64* %7
%39 = add i64 %38, 1
store i64 %39, i64* %7
br label %23
40: ; preds = %23
ret void
}

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