#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 */
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
void char_to_unsigned(char *input, unsigned char *unsig_char) {
  int d;
  size_t i;
  for (i = 0; i < strlen(input) / 2; i++) {
    sscanf(input + i * 2, "%02x", &d);
    unsig_char[i] = (unsigned char)d;
  }
}


x86 assembly (clang, -O0):
<char_to_unsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    11a3 <char_to_unsigned+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rdi
lea    0xe87(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <char_to_unsigned+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_to_unsigned>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
add    $0x1,%eax
cmp    $0x3,%eax
jb     1188 <char_to_unsigned+0x68>
xor    %ebp,%ebp
lea    0xeb9(%rip),%r15
lea    0x4(%rsp),%r12
mov    %r13,%rbx
nop
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
mov    %r13,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0x2,%rbx
cmp    %rax,%rbp
jb     1150 <char_to_unsigned+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define void @char_to_unsigned(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %6
br label %7
7: ; preds = %25, %2
%8 = load i64, i64* %6
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = sdiv i32 %10, 2
%12 = sext i32 %11 to i64
%13 = icmp ult i64 %8, %12
br i1 %13, label %14, label %28
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = load i64, i64* %6
%17 = mul i64 %16, 2
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
%20 = load i32, i32* %5
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %4
%23 = load i64, i64* %6
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %14
%26 = load i64, i64* %6
%27 = add i64 %26, 1
store i64 %27, i64* %6
br label %7
28: ; preds = %7
ret void
}

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