#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 */
struct opctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ outputf(struct opctx *, char *, ...);
int output_safe_get_private(struct opctx *outc, char *class_name, int idx) {
  outputf(outc, "\t%s_private_t *priv;\n", class_name);
  outputf(outc, "\tduk_get_prop_string(ctx, %d, %s_magic_string_private);\n",
          idx, "dukky");
  outputf(outc, "\tpriv = duk_get_pointer(ctx, -1);\n");
  outputf(outc, "\tduk_pop(ctx);\n");
  outputf(outc, "\tif (priv == NULL) return 0;\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<output_safe_get_private>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xece(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xecf(%rip),%rsi
lea    0xf01(%rip),%rcx
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
lea    0xef5(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf06(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf04(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_safe_get_private>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rdx
mov    %rdi,%rbx
lea    0xede(%rip),%rsi
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xee6(%rip),%rsi
lea    0xf18(%rip),%rcx
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xf0b(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xf1d(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xf1c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <outputf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.opctx = type { i32 }
@.str = [22 x i8] c"\09%s_private_t *priv;\0A\00"
@.str.1 = [57 x i8] c"\09duk_get_prop_string(ctx, %d, %s_magic_string_private);\0A\00"
@.str.2 = [6 x i8] c"dukky\00"
@.str.3 = [35 x i8] c"\09priv = duk_get_pointer(ctx, -1);\0A\00"
@.str.4 = [16 x i8] c"\09duk_pop(ctx);\0A\00"
@.str.5 = [31 x i8] c"\09if (priv == NULL) return 0;\0A\0A\00"
define i32 @output_safe_get_private(%struct.opctx* %0, i8* %1, i32 %2) {
%4 = alloca %struct.opctx*
%5 = alloca i8*
%6 = alloca i32
store %struct.opctx* %0, %struct.opctx** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load %struct.opctx*, %struct.opctx** %4
%8 = load i8*, i8** %5
%9 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load %struct.opctx*, %struct.opctx** %4
%11 = load i32, i32* %6
%12 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %10, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = load %struct.opctx*, %struct.opctx** %4
%14 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%15 = load %struct.opctx*, %struct.opctx** %4
%16 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%17 = load %struct.opctx*, %struct.opctx** %4
%18 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.opctx = type { i32 }
@.str = [22 x i8] c"\09%s_private_t *priv;\0A\00"
@.str.1 = [57 x i8] c"\09duk_get_prop_string(ctx, %d, %s_magic_string_private);\0A\00"
@.str.2 = [6 x i8] c"dukky\00"
@.str.3 = [35 x i8] c"\09priv = duk_get_pointer(ctx, -1);\0A\00"
@.str.4 = [16 x i8] c"\09duk_pop(ctx);\0A\00"
@.str.5 = [31 x i8] c"\09if (priv == NULL) return 0;\0A\0A\00"
define i32 @output_safe_get_private(%struct.opctx* %0, i8* %1, i32 %2) {
%4 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}