#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(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
scalar_t__ strtoul(char *, char **, int);
unsigned char *from_command_line_hex(char *arg1, int *data_size) {
  0;
  int input_length = strlen(arg1);
  char current_hex[5] = "0xaa";
  *data_size = input_length / 2;
  unsigned char *data = (unsigned char *)malloc(*data_size);
  int j = 0;
  char *endptr;
  for (int i = 0; i < input_length; i++) {
    memcpy(&(current_hex[2]), &(arg1[2 * i]), 2);
    data[j] = (unsigned char)strtoul(current_hex, &endptr, 16);
    j++;
  }
  return data;
}


x86 assembly (clang, -O0):
<from_command_line_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    0xe9e(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xe99(%rip),%al
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1201 <from_command_line_hex+0xc1>
lea    -0x19(%rbp),%rdi
add    $0x2,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
lea    -0x19(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    119e <from_command_line_hex+0x5e>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_command_line_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
movb   $0x0,0xc(%rsp)
movl   $0x61617830,0x8(%rsp)
61
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
mov    %edi,(%r14)
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11c3 <from_command_line_hex+0x83>
mov    %ebp,%ebp
xor    %r15d,%r15d
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
nop
lea    0xa(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %al,(%r14,%r15,1)
add    $0x1,%r15
add    $0x2,%rbx
cmp    %r15,%rbp
jne    1190 <from_command_line_hex+0x50>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.from_command_line_hex.current_hex = [5 x i8] c"0xaa\00"
define i8* @from_command_line_hex(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [5 x i8]
%4 = alloca i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = sdiv i32 %5, 2
store i32 %7, i32* %1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = bitcast i8** %4 to i8*
%11 = icmp sgt i32 %5, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%14 = zext i32 %5 to i64
br label %16
15: ; preds = %16, %2
ret i8* %9
16: ; preds = %12, %16
%17 = phi i64 [ 0, %12 ], [ %24, %16 ]
%18 = shl nuw nsw i64 %17, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = call i32 @memcpy(i8* %13, i8* %19, i32 2)
%21 = call i64 @strtoul(i8* %6, i8** %4, i32 16)
%22 = trunc i64 %21 to i8
%23 = getelementptr inbounds i8, i8* %9, i64 %17
store i8 %22, i8* %23
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %14
br i1 %25, label %15, label %16
}