#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*/ free(char *);
char *ft_dec_to_hex(char, int);
char *ft_char_to_hex(char *res, char *name) {
  int i;
  int j;
  char *byte;
  i = -1;
  j = 0;
  while (name[++i]) {
    byte = ft_dec_to_hex(name[i], 1);
    res[j++] = byte[0];
    res[j++] = byte[1];
    free(byte);
  }
  return (res);
}


x86 assembly (clang, -O0):
<ft_char_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11b7 <ft_char_to_hex+0x97>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    $0x1,%esi
movsbl (%rax,%rcx,1),%edi
call   1040 <ft_dec_to_hex@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    113e <ft_char_to_hex+0x1e>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_char_to_hex>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rsi),%al
test   %al,%al
je     1173 <ft_char_to_hex+0x53>
mov    %rsi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
mov    $0x1,%esi
call   1040 <ft_dec_to_hex@plt>
movzbl (%rax),%ecx
mov    %cl,(%r15,%rbx,2)
movzbl 0x1(%rax),%ecx
mov    %cl,0x1(%r15,%rbx,2)
mov    %rax,%rdi
call   1030 <free@plt>
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <ft_char_to_hex+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_char_to_hex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %16, %2
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %41
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i8* @ft_dec_to_hex(i8 signext %21, i32 1)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = load i8*, i8** %3
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
%39 = load i8*, i8** %7
%40 = call i32 @free(i8* %39)
br label %8
41: ; preds = %8
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
define i8* @ft_char_to_hex(i8* returned writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2, %5
%6 = phi i64 [ %15, %5 ], [ 0, %2 ]
%7 = phi i64 [ %18, %5 ], [ 0, %2 ]
%8 = phi i8 [ %20, %5 ], [ %3, %2 ]
%9 = tail call i8* @ft_dec_to_hex(i8 signext %8, i32 1)
%10 = load i8, i8* %9
%11 = or i64 %6, 1
%12 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %10, i8* %12
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = add nuw i64 %6, 2
%16 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %14, i8* %16
%17 = tail call i32 @free(i8* %9)
%18 = add nuw i64 %7, 1
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %5, %2
ret i8* %0
}