#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) {
  *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)
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    11d1 <hexToInts+0xa1>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe51(%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    1181 <hexToInts+0x51>
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
mov    %rdi,%r13
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     11c2 <hexToInts+0x92>
lea    0xe8f(%rip),%rsi
mov    %r13,%rdi
mov    %rax,%rdx
call   1050 <sscanf@plt>
cmpq   $0x2,(%r15)
jb     11c2 <hexToInts+0x92>
add    $0x2,%r13
mov    $0x1,%ebx
mov    $0x4,%ebp
lea    0xe69(%rip),%r12
nopw   0x0(%rax,%rax,1)
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     11a0 <hexToInts+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [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 i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = sdiv i32 %9, 2
%11 = sext i32 %10 to i64
%12 = load i64*, i64** %6
store i64 %11, i64* %12
%13 = load i64*, i64** %6
%14 = load i64, i64* %13
%15 = mul i64 %14, 4
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i32*
%18 = load i32**, i32*** %5
store i32* %17, i32** %18
store i64 0, i64* %7
br label %19
19: ; preds = %33, %3
%20 = load i64, i64* %7
%21 = load i64*, i64** %6
%22 = load i64, i64* %21
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %36
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i32**, i32*** %5
%27 = load i32*, i32** %26
%28 = load i64, i64* %7
%29 = getelementptr inbounds i32, i32* %27, i64 %28
%30 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %29)
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 2
store i8* %32, i8** %4
br label %33
33: ; preds = %24
%34 = load i64, i64* %7
%35 = add i64 %34, 1
store i64 %35, i64* %7
br label %19
36: ; preds = %19
ret void
}

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