#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 int uint8_t;

/* Variables and functions */
scalar_t__ is_name(char *, int);
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void nodeid2str(uint8_t *id, char *str) {
  int i;
  if (is_name((char *)id, 15)) {
    memcpy(str, id, 16);
    return;
  }
  for (i = 0; i < 16; i++)
    sprintf(&str[2 * i], "%02x", id[i]);
  for (i = 31; str[i] == '0'; i--)
    str[i] = 0;
}


x86 assembly (clang, -O0):
<nodeid2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xf,%esi
call   1040 <is_name@plt>
cmp    $0x0,%rax
je     116f <nodeid2str+0x3f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
jmp    11ea <nodeid2str+0xba>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jge    11b4 <nodeid2str+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe5f(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <nodeid2str+0x46>
movl   $0x1f,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    11ea <nodeid2str+0xba>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11bb <nodeid2str+0x8b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nodeid2str>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0xf,%esi
call   1040 <is_name@plt>
test   %rax,%rax
je     115f <nodeid2str+0x2f>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <memcpy@plt>
mov    (%r14),%edx
lea    0xe97(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x2(%rbx),%rdi
mov    0x4(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x4(%rbx),%rdi
mov    0x8(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x6(%rbx),%rdi
mov    0xc(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x8(%rbx),%rdi
mov    0x10(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0xa(%rbx),%rdi
mov    0x14(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0xc(%rbx),%rdi
mov    0x18(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0xe(%rbx),%rdi
mov    0x1c(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x10(%rbx),%rdi
mov    0x20(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x12(%rbx),%rdi
mov    0x24(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x14(%rbx),%rdi
mov    0x28(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x16(%rbx),%rdi
mov    0x2c(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x18(%rbx),%rdi
mov    0x30(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x1a(%rbx),%rdi
mov    0x34(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x1c(%rbx),%rdi
mov    0x38(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
lea    0x1e(%rbx),%rdi
mov    0x3c(%r14),%edx
mov    %r15,%rsi
call   1050 <sprintf@plt>
cmpb   $0x30,0x1f(%rbx)
jne    127d <nodeid2str+0x14d>
add    $0x1f,%rbx
xchg   %ax,%ax
movb   $0x0,(%rbx)
cmpb   $0x30,-0x1(%rbx)
lea    -0x1(%rbx),%rbx
je     1270 <nodeid2str+0x140>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @nodeid2str(i32* %0, i8* %1) {
%3 = bitcast i32* %0 to i8*
%4 = tail call i64 @is_name(i8* %3, i32 15)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %72
6: ; preds = %2
%7 = load i32, i32* %0
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds i8, i8* %1, i64 2
%10 = getelementptr inbounds i32, i32* %0, i64 1
%11 = load i32, i32* %10
%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), i32 %11)
%13 = getelementptr inbounds i8, i8* %1, i64 4
%14 = getelementptr inbounds i32, i32* %0, i64 2
%15 = load i32, i32* %14
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds i8, i8* %1, i64 6
%18 = getelementptr inbounds i32, i32* %0, i64 3
%19 = load i32, i32* %18
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i8, i8* %1, i64 8
%22 = getelementptr inbounds i32, i32* %0, i64 4
%23 = load i32, i32* %22
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds i8, i8* %1, i64 10
%26 = getelementptr inbounds i32, i32* %0, i64 5
%27 = load i32, i32* %26
%28 = tail call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds i8, i8* %1, i64 12
%30 = getelementptr inbounds i32, i32* %0, i64 6
%31 = load i32, i32* %30
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %1, i64 14
%34 = getelementptr inbounds i32, i32* %0, i64 7
%35 = load i32, i32* %34
%36 = tail call i32 @sprintf(i8* dereferenceable(1) %33, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds i8, i8* %1, i64 16
%38 = getelementptr inbounds i32, i32* %0, i64 8
%39 = load i32, i32* %38
%40 = tail call i32 @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds i8, i8* %1, i64 18
%42 = getelementptr inbounds i32, i32* %0, i64 9
%43 = load i32, i32* %42
%44 = tail call i32 @sprintf(i8* dereferenceable(1) %41, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds i8, i8* %1, i64 20
%46 = getelementptr inbounds i32, i32* %0, i64 10
%47 = load i32, i32* %46
%48 = tail call i32 @sprintf(i8* dereferenceable(1) %45, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds i8, i8* %1, i64 22
%50 = getelementptr inbounds i32, i32* %0, i64 11
%51 = load i32, i32* %50
%52 = tail call i32 @sprintf(i8* dereferenceable(1) %49, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds i8, i8* %1, i64 24
%54 = getelementptr inbounds i32, i32* %0, i64 12
%55 = load i32, i32* %54
%56 = tail call i32 @sprintf(i8* dereferenceable(1) %53, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds i8, i8* %1, i64 26
%58 = getelementptr inbounds i32, i32* %0, i64 13
%59 = load i32, i32* %58
%60 = tail call i32 @sprintf(i8* dereferenceable(1) %57, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds i8, i8* %1, i64 28
%62 = getelementptr inbounds i32, i32* %0, i64 14
%63 = load i32, i32* %62
%64 = tail call i32 @sprintf(i8* dereferenceable(1) %61, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds i8, i8* %1, i64 30
%66 = getelementptr inbounds i32, i32* %0, i64 15
%67 = load i32, i32* %66
%68 = tail call i32 @sprintf(i8* dereferenceable(1) %65, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds i8, i8* %1, i64 31
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 48
br i1 %71, label %74, label %81
72: ; preds = %2
%73 = tail call i32 @memcpy(i8* %1, i32* %0, i32 16)
br label %81
74: ; preds = %6, %74
%75 = phi i64 [ %77, %74 ], [ 31, %6 ]
%76 = phi i8* [ %78, %74 ], [ %69, %6 ]
store i8 0, i8* %76
%77 = add nsw i64 %75, -1
%78 = getelementptr inbounds i8, i8* %1, i64 %77
%79 = load i8, i8* %78
%80 = icmp eq i8 %79, 48
br i1 %80, label %74, label %81
81: ; preds = %74, %6, %72
ret void
}