#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 scalar_t__ uint8_t;
typedef scalar_t__ uint64_t;
typedef scalar_t__ uint16_t;
typedef scalar_t__ int8_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(scalar_t__ *, char *, scalar_t__);
int strlen(scalar_t__ *);
uint8_t *vector_str(uint8_t *buffer, uint64_t *vector, uint16_t size) {
  int8_t i;
  *buffer = 0;
  for (i = size - 1; i >= 0; i--)
    if (strlen(buffer))
      sprintf(buffer + strlen(buffer), "%016llx", *(vector + i));
    else if (*(vector + i) != 0)
      sprintf(buffer + strlen(buffer), "%llx", *(vector + i));
  return buffer;
}


x86 assembly (clang, -O0):
<vector_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jl     1207 <vector_str+0xe7>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     11a3 <vector_str+0x83>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe67(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11f1 <vector_str+0xd1>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ec <vector_str+0xcc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe21(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11f1 <vector_str+0xd1>
jmp    11f6 <vector_str+0xd6>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    114b <vector_str+0x2b>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_str>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
movq   $0x0,(%rdi)
test   %rdx,%rdx
jle    11b1 <vector_str+0x91>
mov    %rdx,%rbx
mov    %rsi,%r15
add    $0x1,%rbx
lea    0xebf(%rip),%r12
lea    0xeb0(%rip),%r13
jmp    1185 <vector_str+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,8),%rdi
mov    -0x10(%r15,%rbx,8),%rdx
mov    %r13,%rsi
call   1040 <sprintf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11b1 <vector_str+0x91>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jne    1160 <vector_str+0x40>
cmpq   $0x0,-0x10(%r15,%rbx,8)
je     117b <vector_str+0x5b>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
lea    (%r14,%rax,8),%rdi
mov    -0x10(%r15,%rbx,8),%rdx
mov    %r12,%rsi
jmp    1176 <vector_str+0x56>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"%016llx\00"
@.str.1 = [5 x i8] c"%llx\00"
define i64* @vector_str(i64* returned %0, i64* nocapture %1, i64 %2) {
store i64 0, i64* %0
%4 = icmp sgt i64 %2, 0
br i1 %4, label %5, label %29
5: ; preds = %3, %27
%6 = phi i64 [ %7, %27 ], [ %2, %3 ]
%7 = add nsw i64 %6, -1
%8 = tail call i32 @strlen(i64* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = tail call i32 @strlen(i64* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i64, i64* %0, i64 %12
%14 = getelementptr inbounds i64, i64* %1, i64 %7
%15 = load i64, i64* %14
%16 = tail call i32 @sprintf(i64* %13, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %27
17: ; preds = %5
%18 = getelementptr inbounds i64, i64* %1, i64 %7
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = tail call i32 @strlen(i64* %0)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i64, i64* %0, i64 %23
%25 = load i64, i64* %18
%26 = tail call i32 @sprintf(i64* %24, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %10, %21, %17
%28 = icmp ugt i64 %6, 1
br i1 %28, label %5, label %29
29: ; preds = %27, %3
ret i64* %0
}