#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 *strtok(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
char *hexToStr(char *buffer) {
  int ch, i = 0;
  char *hexch;
  char str[16384 * 4] = "";
  hexch = strtok(buffer, " ");
  while (hexch != NULL) {
    ch = (int)strtol(hexch, NULL, 16);
    str[i] = ch;
    hexch = strtok(NULL, " ");
    i++;
  }
  return str;
}


x86 assembly (clang, -O0):
<hexToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x10020(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bf <hexToStr+0x8f>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x10020(%rbp,%rax,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe58(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <hexToStr+0x3d>
lea    -0x10020(%rbp),%rax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexToStr>:
push   %r14
push   %rbx
sub    $0x10008,%rsp
lea    0xecf(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1174 <hexToStr+0x54>
mov    %rsp,%rbx
lea    0xebb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,(%rbx)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <hexToStr+0x30>
mov    %rsp,%rax
add    $0x10008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i8* @hexToStr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [65536 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
%7 = bitcast [65536 x i8]* %6 to i8*
%8 = load i8*, i8** %2
%9 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %5
br label %10
10: ; preds = %13, %1
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = call i64 @strtol(i8* %14, i32* null, i32 16)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %20
store i8 %18, i8* %21
%22 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %5
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %10
%26 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define noalias i8* @hexToStr(i8* %0) {
%2 = alloca [65536 x i8]
%3 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %15, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %13, %6 ], [ 0, %1 ]
%8 = phi i8* [ %12, %6 ], [ %4, %1 ]
%9 = tail call i64 @strtol(i8* nocapture %8, i32* null, i32 16)
%10 = trunc i64 %9 to i8
%11 = getelementptr inbounds [65536 x i8], [65536 x i8]* %2, i64 0, i64 %7
store i8 %10, i8* %11
%12 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = add nuw i64 %7, 1
%14 = icmp eq i8* %12, null
br i1 %14, label %15, label %6
15: ; preds = %6, %1
ret i8* %3
}