#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 */
char const *string_ret_const();
char *native_string_callback(const char *(*str_ret)()) {
  const char *str = str_ret();
  if (str == NULL) {
    return "null";
  } else if (str == string_ret_const()) {
    return "same";
  } else {
    return "different";
  }
}


x86 assembly (clang, -O0):
<native_string_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   *-0x10(%rbp)
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1140 <native_string_callback+0x30>
lea    0xec9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    117a <native_string_callback+0x6a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <string_ret_const@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    116f <native_string_callback+0x5f>
lea    0xe9f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    117a <native_string_callback+0x6a>
lea    0xe94(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<native_string_callback>:
push   %rbx
xor    %eax,%eax
call   *%rdi
test   %rax,%rax
je     113b <native_string_callback+0x2b>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <string_ret_const@plt>
cmp    %rax,%rbx
lea    0xed7(%rip),%rcx
lea    0xed5(%rip),%rax
cmove  %rcx,%rax
pop    %rbx
ret
lea    0xebe(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"null\00"
@.str.1 = [5 x i8] c"same\00"
@.str.2 = [10 x i8] c"different\00"
define i8* @native_string_callback(i8* (...)* %0) {
%2 = alloca i8*
%3 = alloca i8* (...)*
%4 = alloca i8*
store i8* (...)* %0, i8* (...)** %3
%5 = load i8* (...)*, i8* (...)** %3
%6 = call i8* (...) %5()
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %16
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i8* (...) @string_ret_const()
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %16
15: ; preds = %10
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %16
16: ; preds = %15, %14, %9
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"null\00"
@.str.1 = [5 x i8] c"same\00"
@.str.2 = [10 x i8] c"different\00"
define i8* @native_string_callback(i8* (...)* nocapture %0) {
%2 = tail call i8* (...) %0()
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i8* (...) @string_ret_const()
%6 = icmp eq i8* %2, %5
%7 = select i1 %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
br label %8
8: ; preds = %4, %1
%9 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ %7, %4 ]
ret i8* %9
}