#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*/ MemSet(char *, int /*<<< orphan*/, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *Stream(char *data, int size) {
  int i, j, slen;
  char *r;
  static char hexa[17] = "abcdefghijklmnop";
  slen = 10 + size * 2 + 1;
  r = (char *)malloc(slen);
  if (!r)
    return 0;
  MemSet(r, 0, slen);
  sprintf(r, "%.10d", size);
  j = 10;
  for (i = 0; i < size; i++) {
    r[j++] = hexa[((unsigned char)data[i]) / 16];
    r[j++] = hexa[((unsigned char)data[i]) % 16];
  }
  return r;
}


x86 assembly (clang, -O0):
<Stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0xa,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1172 <Stream+0x42>
movq   $0x0,-0x8(%rbp)
jmp    122f <Stream+0xff>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1040 <MemSet@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe72(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0xa,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1227 <Stream+0xf7>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
lea    0x2e75(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0x2e3f(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <Stream+0x71>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Stream>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    (%r15,%r15,1),%ebp
add    $0xb,%ebp
mov    %ebp,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     11bc <Stream+0x8c>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <MemSet@plt>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1050 <sprintf@plt>
test   %r15d,%r15d
jle    11be <Stream+0x8e>
mov    %r15d,%edi
xor    %ecx,%ecx
lea    0xe7e(%rip),%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%rcx,1),%esi
shr    $0x4,%rsi
movzbl (%rsi,%rdx,1),%eax
mov    %al,0xa(%rbx,%rcx,2)
movzbl (%r14,%rcx,1),%eax
and    $0xf,%eax
movzbl (%rax,%rdx,1),%eax
mov    %al,0xb(%rbx,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%rdi
jne    1190 <Stream+0x60>
jmp    11be <Stream+0x8e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@Stream.hexa = internal global [17 x i8] c"abcdefghijklmnop\00"
@.str = [6 x i8] c"%.10d\00"
define i8* @Stream(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = mul nsw i32 %10, 2
%12 = add nsw i32 10, %11
%13 = add nsw i32 %12, 1
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %2
store i8* null, i8** %3
br label %67
20: ; preds = %2
%21 = load i8*, i8** %9
%22 = load i32, i32* %8
%23 = call i32 @MemSet(i8* %21, i32 0, i32 %22)
%24 = load i8*, i8** %9
%25 = load i32, i32* %5
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 10, i32* %7
store i32 0, i32* %6
br label %27
27: ; preds = %62, %20
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %65
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = sdiv i32 %37, 16
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* @Stream.hexa, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = load i8*, i8** %9
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 %41, i8* %46
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = srem i32 %52, 16
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [17 x i8], [17 x i8]* @Stream.hexa, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = load i8*, i8** %9
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
store i8 %56, i8* %61
br label %62
62: ; preds = %31
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %27
65: ; preds = %27
%66 = load i8*, i8** %9
store i8* %66, i8** %3
br label %67
67: ; preds = %65, %19
%68 = load i8*, i8** %3
ret i8* %68
}

LLVM IR (-O2):
@Stream.hexa = internal unnamed_addr constant [17 x i8] c"abcdefghijklmnop\00"
@.str = [6 x i8] c"%.10d\00"
define i8* @Stream(i8* nocapture %0, i32 %1) {
%3 = shl nsw i32 %1, 1
%4 = add nsw i32 %3, 11
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = tail call i32 @MemSet(i8* %6, i32 0, i32 %4)
%10 = tail call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %34
12: ; preds = %8
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 10, %12 ], [ %30, %14 ]
%16 = phi i64 [ 0, %12 ], [ %32, %14 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = lshr i8 %18, 4
%20 = zext i8 %19 to i64
%21 = getelementptr inbounds [17 x i8], [17 x i8]* @Stream.hexa, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = or i64 %15, 1
%24 = getelementptr inbounds i8, i8* %6, i64 %15
store i8 %22, i8* %24
%25 = load i8, i8* %17
%26 = and i8 %25, 15
%27 = zext i8 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @Stream.hexa, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = add nuw nsw i64 %15, 2
%31 = getelementptr inbounds i8, i8* %6, i64 %23
store i8 %29, i8* %31
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %34, label %14
34: ; preds = %14, %8, %2
%35 = phi i8* [ null, %2 ], [ %6, %8 ], [ %6, %14 ]
ret i8* %35
}