#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
unsigned int strlen(char *);
void BM_WriteHexString(FILE *fptr, char *s) {
  unsigned int i;
  int c;
  char hex[3];
  for (i = 0; i < strlen(s); i += 2) {
    hex[0] = s[i];
    hex[1] = s[i + 1];
    hex[2] = '\0';
    sscanf(hex, "%X", &c);
    putc(c, fptr);
  }
}


x86 assembly (clang, -O0):
<BM_WriteHexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jae    11b4 <BM_WriteHexString+0x84>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1b(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1a(%rbp)
movb   $0x0,-0x19(%rbp)
lea    -0x1b(%rbp),%rdi
lea    0xe6f(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <putc@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <BM_WriteHexString+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BM_WriteHexString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11a3 <BM_WriteHexString+0x73>
xor    %ebp,%ebp
lea    0xeaa(%rip),%r15
lea    0x1(%rsp),%r12
lea    0x4(%rsp),%r13
mov    %ebp,%eax
movzbl (%rbx,%rax,1),%eax
mov    %al,0x1(%rsp)
lea    0x1(%rbp),%eax
movzbl (%rbx,%rax,1),%eax
mov    %al,0x2(%rsp)
movb   $0x0,0x3(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <sscanf@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1040 <putc@plt>
add    $0x2,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jb     1160 <BM_WriteHexString+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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