#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 */
char *ft_convert_base(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ ft_itoa(int);
char *ft_strfjoin(char *, char *, int, int);
char *ft_strfjoinnchar(char *, int, int /*<<< orphan*/);
int ft_strlen(char *);
char *ft_strnew(int /*<<< orphan*/);
char *ft_strfhex(char *c) {
  int i;
  char *s;
  char *tmp;
  s = ft_strnew(0);
  i = -1;
  while (c[++i]) {
    tmp = ft_strfjoin(
        ft_convert_base(ft_itoa((int)c[i]), "0123456789", "0123456789ABCDEF"),
        " ", 1, 0);
    if (ft_strlen(tmp) == 2)
      tmp = ft_strfjoinnchar(tmp, 1, '0');
    s = ft_strfjoin(s, tmp, 1, 1);
  }
  if (ft_strlen(s) > 1)
    s[ft_strlen(s) - 1] = '\0';
  return (s);
}


x86 assembly (clang, -O0):
<ft_strfhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   1070 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
movslq %ecx,%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     121e <ft_strfhex+0xbe>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <ft_itoa@plt>
mov    %eax,%edi
lea    0xe4e(%rip),%rsi
lea    0xe52(%rip),%rdx
call   1080 <ft_convert_base@plt>
mov    %rax,%rdi
lea    0xe54(%rip),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <ft_strfjoin@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ft_strlen@plt>
cmp    $0x2,%eax
jne    1201 <ft_strfhex+0xa1>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x30,%edx
call   1030 <ft_strfjoinnchar@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1060 <ft_strfjoin@plt>
mov    %rax,-0x18(%rbp)
jmp    117e <ft_strfhex+0x1e>
mov    -0x18(%rbp),%rdi
call   1050 <ft_strlen@plt>
cmp    $0x1,%eax
jle    1251 <ft_strfhex+0xf1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strfhex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
call   1070 <ft_strnew@plt>
mov    %rax,%r14
mov    (%rbx),%al
test   %al,%al
je     1211 <ft_strfhex+0xb1>
add    $0x1,%rbx
lea    0xe73(%rip),%r15
lea    0xe77(%rip),%r12
lea    0xe81(%rip),%r13
jmp    11c3 <ft_strfhex+0x63>
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    $0x1,%ecx
call   1060 <ft_strfjoin@plt>
mov    %rax,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1211 <ft_strfhex+0xb1>
movsbl %al,%edi
call   1040 <ft_itoa@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <ft_convert_base@plt>
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <ft_strfjoin@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <ft_strlen@plt>
cmp    $0x2,%eax
jne    11a0 <ft_strfhex+0x40>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x30,%edx
call   1030 <ft_strfjoinnchar@plt>
mov    %rax,%rbp
jmp    11a0 <ft_strfhex+0x40>
mov    %r14,%rdi
call   1050 <ft_strlen@plt>
cmp    $0x2,%eax
jl     122e <ft_strfhex+0xce>
mov    %r14,%rdi
call   1050 <ft_strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [17 x i8] c"0123456789ABCDEF\00"
@.str.2 = [2 x i8] c" \00"
define i8* @ft_strfhex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @ft_strnew(i32 0)
store i8* %6, i8** %4
store i32 -1, i32* %3
br label %7
7: ; preds = %31, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %7
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 @ft_itoa(i32 %21)
%23 = call i8* @ft_convert_base(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%24 = call i8* @ft_strfjoin(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 0)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = call i32 @ft_strlen(i8* %25)
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = load i8*, i8** %5
%30 = call i8* @ft_strfjoinnchar(i8* %29, i32 1, i32 48)
store i8* %30, i8** %5
br label %31
31: ; preds = %28, %15
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = call i8* @ft_strfjoin(i8* %32, i8* %33, i32 1, i32 1)
store i8* %34, i8** %4
br label %7
35: ; preds = %7
%36 = load i8*, i8** %4
%37 = call i32 @ft_strlen(i8* %36)
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = load i8*, i8** %4
%42 = call i32 @ft_strlen(i8* %41)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %39, %35
%47 = load i8*, i8** %4
ret i8* %47
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [17 x i8] c"0123456789ABCDEF\00"
@.str.2 = [2 x i8] c" \00"
define i8* @ft_strfhex(i8* nocapture %0) {
%2 = tail call i8* @ft_strnew(i32 0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1, %17
%6 = phi i64 [ %20, %17 ], [ 0, %1 ]
%7 = phi i8 [ %22, %17 ], [ %3, %1 ]
%8 = phi i8* [ %19, %17 ], [ %2, %1 ]
%9 = sext i8 %7 to i32
%10 = tail call i32 @ft_itoa(i32 %9)
%11 = tail call i8* @ft_convert_base(i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i8* @ft_strfjoin(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 0)
%13 = tail call i32 @ft_strlen(i8* %12)
%14 = icmp eq i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = tail call i8* @ft_strfjoinnchar(i8* %12, i32 1, i32 48)
br label %17
17: ; preds = %15, %5
%18 = phi i8* [ %16, %15 ], [ %12, %5 ]
%19 = tail call i8* @ft_strfjoin(i8* %8, i8* %18, i32 1, i32 1)
%20 = add nuw i64 %6, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %17, %1
%25 = phi i8* [ %2, %1 ], [ %19, %17 ]
%26 = tail call i32 @ft_strlen(i8* %25)
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = tail call i32 @ft_strlen(i8* %25)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %25, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28, %24
ret i8* %25
}