#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 char);
const char *guid_str(const char *guid) {
  static char buf[24 * 2 + 1];
  int i;
  char *p = buf;
  for (i = 0; i < 24; i++) {
    unsigned char c = guid[i];
    if (c >= 32 && c < 127)
      p += sprintf(p, "%c", c);
    else
      p += sprintf(p, "%02x", c);
  }
  *p = '\0';
  return (const char *)buf;
}


x86 assembly (clang, -O0):
<guid_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f1d(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x18,-0xc(%rbp)
jge    11c0 <guid_str+0xb0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jl     1189 <guid_str+0x79>
movzbl -0x19(%rbp),%eax
cmp    $0x7f,%eax
jge    1189 <guid_str+0x79>
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
movzbl -0x19(%rbp),%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11ad <guid_str+0x9d>
mov    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
movzbl -0x19(%rbp),%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    11b2 <guid_str+0xa2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112e <guid_str+0x1e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e72(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guid_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x2f1e(%rip),%r12
xor    %ebx,%ebx
lea    0xed5(%rip),%r15
jmp    114d <guid_str+0x3d>
nopl   (%rax)
movzbl %al,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <sprintf@plt>
cltq
add    %rax,%r12
add    $0x1,%rbx
cmp    $0x18,%rbx
je     116b <guid_str+0x5b>
movzbl (%r14,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5e,%cl
ja     1130 <guid_str+0x20>
mov    %al,(%r12)
movb   $0x0,0x1(%r12)
mov    $0x1,%eax
jmp    113e <guid_str+0x2e>
movb   $0x0,(%r12)
lea    0x2ec9(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@guid_str.buf = internal global [49 x i8] zeroinitializer
@.str = [3 x i8] c"%c\00"
@.str.1 = [5 x i8] c"%02x\00"
define i8* @guid_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @guid_str.buf, i64 0, i64 0), i8** %4
store i32 0, i32* %3
br label %6
6: ; preds = %37, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 24
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %5
%15 = load i8, i8* %5
%16 = zext i8 %15 to i32
%17 = icmp sge i32 %16, 32
br i1 %17, label %18, label %29
18: ; preds = %9
%19 = load i8, i8* %5
%20 = zext i8 %19 to i32
%21 = icmp slt i32 %20, 127
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = load i8, i8* %5
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = load i8*, i8** %4
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %4
br label %36
29: ; preds = %18, %9
%30 = load i8*, i8** %4
%31 = load i8, i8* %5
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %31)
%33 = load i8*, i8** %4
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %4
br label %36
36: ; preds = %29, %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %6
40: ; preds = %6
%41 = load i8*, i8** %4
store i8 0, i8* %41
ret i8* getelementptr inbounds ([49 x i8], [49 x i8]* @guid_str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@guid_str.buf = internal global [49 x i8] zeroinitializer
@.str.1 = [5 x i8] c"%02x\00"
define i8* @guid_str(i8* nocapture %0) {
br label %2
2: ; preds = %1, %13
%3 = phi i64 [ 0, %1 ], [ %17, %13 ]
%4 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @guid_str.buf, i64 0, i64 0), %1 ], [ %16, %13 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
%7 = add i8 %6, -32
%8 = icmp ult i8 %7, 95
br i1 %8, label %9, label %11
9: ; preds = %2
store i8 %6, i8* %4
%10 = getelementptr i8, i8* %4, i64 1
store i8 0, i8* %10
br label %13
11: ; preds = %2
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %6)
br label %13
13: ; preds = %11, %9
%14 = phi i32 [ 1, %9 ], [ %12, %11 ]
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = add nuw nsw i64 %3, 1
%18 = icmp eq i64 %17, 24
br i1 %18, label %19, label %2
19: ; preds = %13
store i8 0, i8* %16
ret i8* getelementptr inbounds ([49 x i8], [49 x i8]* @guid_str.buf, i64 0, i64 0)
}