#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 /*<<< orphan*/ fptr;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *wcsutil_fptr2str(void (*fptr)(void), char hext[19]) {
  int *(ip[2]), j[2], le = 1;
  ip[0] = j;
  ip[1] = j + 1;
  unsigned char *p = (unsigned char *)(&fptr);
  if ((unsigned char *)ip[0] < (unsigned char *)ip[1]) {
    p += sizeof(fptr) - 1;
    le = -1;
  }
  char *t = hext;
  sprintf(t, "0x0");
  t += 2;
  for (size_t i = 0; i < sizeof(fptr); i++) {
    int gotone = 0;
    if (*p)
      gotone = 1;
    if (gotone) {
      sprintf(t, "%02x", *p);
      t += 2;
    }
    p += le;
  }
  return hext;
}


x86 assembly (clang, -O0):
<wcsutil_fptr2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x2c(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    %rcx,%rax
jae    1167 <wcsutil_fptr2str+0x57>
mov    -0x38(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x38(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x8,-0x48(%rbp)
jae    120c <wcsutil_fptr2str+0xfc>
movl   $0x0,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     11bb <wcsutil_fptr2str+0xab>
movl   $0x1,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     11ea <wcsutil_fptr2str+0xda>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
movzbl (%rax),%edx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1195 <wcsutil_fptr2str+0x85>
mov    -0x10(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcsutil_fptr2str>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x307830,(%rsi)
lea    0x2(%rsi),%rbx
mov    %rdi,%rdx
shr    $0x38,%rdx
je     1143 <wcsutil_fptr2str+0x33>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x4(%r14),%rbx
mov    %r15,%rax
shr    $0x30,%rax
test   %al,%al
je     1166 <wcsutil_fptr2str+0x56>
movzbl %al,%edx
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
mov    %r15,%rax
shr    $0x28,%rax
test   %al,%al
je     1189 <wcsutil_fptr2str+0x79>
movzbl %al,%edx
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
mov    %r15,%rax
shr    $0x20,%rax
test   %al,%al
je     11ac <wcsutil_fptr2str+0x9c>
movzbl %al,%edx
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
mov    %r15,%rax
shr    $0x18,%rax
test   %al,%al
je     11cf <wcsutil_fptr2str+0xbf>
movzbl %al,%edx
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
mov    %r15,%rax
shr    $0x10,%rax
test   %al,%al
je     11f2 <wcsutil_fptr2str+0xe2>
movzbl %al,%edx
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
mov    %r15,%rax
shr    $0x8,%rax
test   %al,%al
je     1215 <wcsutil_fptr2str+0x105>
movzbl %al,%edx
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0x2,%rbx
test   %r15b,%r15b
je     122f <wcsutil_fptr2str+0x11f>
movzbl %r15b,%edx
lea    0xddb(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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