#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
void irc_info_create_string_with_pointer(char **string, void *pointer) {
  if (*string) {
    free(*string);
    *string = NULL;
  }
  if (pointer) {
    *string = malloc(64);
    if (*string) {
      snprintf(*string, 64 - 1, "0x%lx", (long unsigned int)pointer);
    }
  }
}


x86 assembly (clang, -O0):
<irc_info_create_string_with_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1165 <irc_info_create_string_with_pointer+0x35>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11b3 <irc_info_create_string_with_pointer+0x83>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ae <irc_info_create_string_with_pointer+0x7e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3f,%esi
lea    0xe57(%rip),%rdx
call   1040 <snprintf@plt>
jmp    11b3 <irc_info_create_string_with_pointer+0x83>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_info_create_string_with_pointer>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     114e <irc_info_create_string_with_pointer+0x1e>
call   1030 <free@plt>
movq   $0x0,(%rbx)
test   %r14,%r14
je     1183 <irc_info_create_string_with_pointer+0x53>
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1183 <irc_info_create_string_with_pointer+0x53>
lea    0xe94(%rip),%rdx
mov    %rax,%rdi
mov    $0x3f,%esi
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <snprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"0x%lx\00"
define void @irc_info_create_string_with_pointer(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%5 = load i8**, i8*** %3
%6 = load i8*, i8** %5
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = call i32 @free(i8* %10)
%12 = load i8**, i8*** %3
store i8* null, i8** %12
br label %13
13: ; preds = %8, %2
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = call i8* @malloc(i32 64)
%18 = load i8**, i8*** %3
store i8* %17, i8** %18
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8**, i8*** %3
%24 = load i8*, i8** %23
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %25 to i64
%27 = call i32 @snprintf(i8* %24, i32 63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %22, %16
br label %29
29: ; preds = %28, %13
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"0x%lx\00"
define void @irc_info_create_string_with_pointer(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @free(i8* %3)
store i8* null, i8** %0
br label %7
7: ; preds = %5, %2
%8 = icmp eq i8* %1, null
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
store i8* %10, i8** %0
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = ptrtoint i8* %1 to i64
%14 = tail call i32 @snprintf(i8* %10, i32 63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %9, %12, %7
ret void
}