#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*/ sprintf(char *, char *, unsigned long);
int /*<<< orphan*/ strlen(char *);
short int ipv4_integer2hex(unsigned long ip_int, char *ip_hex) {
  int i = 3;
  for (; i >= 0; i--) {
    sprintf(ip_hex, "%02X", (ip_int >> (i * 8)) & 0xFF);
    ip_hex += strlen(ip_hex);
    if (i != 0)
      *ip_hex++ = '.';
  }
  return 0;
}


x86 assembly (clang, -O0):
<ipv4_integer2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11b1 <ipv4_integer2hex+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
mov    %eax,%eax
mov    %eax,%ecx
shr    %cl,%rdx
and    $0xff,%rdx
lea    0xe9c(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     119e <ipv4_integer2hex+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2e,(%rax)
jmp    11a3 <ipv4_integer2hex+0x83>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <ipv4_integer2hex+0x17>
xor    %eax,%eax
cwtl
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_integer2hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%edx
mov    %rdi,%r13
shr    $0x18,%edx
lea    0xec5(%rip),%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%r12
lea    (%rbx,%rax,1),%r15
add    $0x1,%r15
movb   $0x2e,(%rbx,%rax,1)
mov    %r13d,%eax
shr    $0x10,%eax
movzbl %al,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r12,1),%r15
add    $0x1,%r15
lea    0x2(%rax,%r12,1),%rbx
movb   $0x2e,0x1(%rax,%r12,1)
mov    %r13,%rax
movzbl %ah,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%r15,1),%rbx
add    $0x2,%rbx
movb   $0x2e,0x1(%rax,%r15,1)
movzbl %r13b,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define signext i16 @ipv4_integer2hex(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
store i32 3, i32* %5
br label %6
6: ; preds = %29, %2
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = load i8*, i8** %4
%11 = load i64, i64* %3
%12 = load i32, i32* %5
%13 = mul nsw i32 %12, 8
%14 = zext i32 %13 to i64
%15 = lshr i64 %11, %14
%16 = and i64 %15, 255
%17 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %4
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %9
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
store i8 46, i8* %26
br label %28
28: ; preds = %25, %9
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, -1
store i32 %31, i32* %5
br label %6
32: ; preds = %6
ret i16 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define signext i16 @ipv4_integer2hex(i64 %0, i8* %1) {
%3 = lshr i64 %0, 24
%4 = and i64 %3, 255
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 46, i8* %8
%10 = lshr i64 %0, 16
%11 = and i64 %10, 255
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %11)
%13 = tail call i32 @strlen(i8* %9)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 46, i8* %15
%17 = lshr i64 %0, 8
%18 = and i64 %17, 255
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = tail call i32 @strlen(i8* %16)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 46, i8* %22
%24 = and i64 %0, 255
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %24)
%26 = tail call i32 @strlen(i8* %23)
ret i16 0
}