#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 *, unsigned int *);
void ascii_to_hex(unsigned char *buffer, int n) {
  char ascii[3];
  ascii[2] = '\0';
  unsigned int hex;
  for (int i = 0; i < n - 1; i += 2) {
    ascii[0] = buffer[i];
    ascii[1] = buffer[i + 1];
    sscanf(ascii, "%02x", &hex);
    buffer[i / 2] = (((unsigned char)hex) & 0xff);
  }
  return;
}


x86 assembly (clang, -O0):
<ascii_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ae <ascii_to_hex+0x9e>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xf(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xe(%rbp)
lea    -0xf(%rbp),%rdi
lea    0xe99(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x14(%rbp),%eax
movzbl %al,%eax
and    $0xff,%eax
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x21(%rbp),%dl
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <ascii_to_hex+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii_to_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x3(%rsp)
cmp    $0x2,%esi
jl     117a <ascii_to_hex+0x6a>
mov    %esi,%r13d
mov    %rdi,%rbx
add    $0xffffffff,%r13d
xor    %ebp,%ebp
lea    0x1(%rsp),%r15
lea    0x4(%rsp),%r12
xor    %r14d,%r14d
xchg   %ax,%ax
movzbl (%rbx,%r14,1),%eax
mov    %al,0x1(%rsp)
movzbl 0x1(%rbx,%r14,1),%eax
mov    %al,0x2(%rsp)
mov    %r15,%rdi
lea    0xea3(%rip),%rsi
mov    %r12,%rdx
call   1030 <sscanf@plt>
movzbl 0x4(%rsp),%eax
mov    %al,(%rbx,%rbp,1)
add    $0x2,%r14
add    $0x1,%rbp
cmp    %r14d,%r13d
jg     1140 <ascii_to_hex+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 @ascii_to_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %8
store i32 0, i32* %7
br label %9
9: ; preds = %40, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %43
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %19, i8* %20
%21 = load i8*, i8** %3
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %26, i8* %27
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %6)
%30 = load i32, i32* %6
%31 = trunc i32 %30 to i8
%32 = zext i8 %31 to i32
%33 = and i32 %32, 255
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %3
%36 = load i32, i32* %7
%37 = sdiv i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 %34, i8* %39
br label %40
40: ; preds = %14
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 2
store i32 %42, i32* %7
br label %9
43: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @ascii_to_hex(i8* nocapture %0, i32 %1) {
%3 = alloca [3 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %6
%7 = bitcast i32* %4 to i8*
%8 = add nsw i32 %1, -1
%9 = icmp sgt i32 %1, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
br label %13
12: ; preds = %13, %2
ret void
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %25, %13 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = or i64 %14, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %11
%20 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i8
%23 = lshr exact i64 %14, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 %22, i8* %24
%25 = add nuw i64 %14, 2
%26 = trunc i64 %25 to i32
%27 = icmp sgt i32 %8, %26
br i1 %27, label %13, label %12
}