#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_set_destructor(struct opctx *outc, char *class_name, int idx) {
  outputf(outc, "\t/* Set the destructor */\n");
  outputf(outc, "\tduk_dup(ctx, %d);\n", idx);
  outputf(outc, "\tduk_push_c_function(ctx, %s_%s___destructor, 1);\n", "dukky",
          class_name);
  outputf(outc, "\tduk_set_finalizer(ctx, -2);\n");
  outputf(outc, "\tduk_pop(ctx);\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<output_set_destructor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xed8(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    0xed6(%rip),%rsi
lea    0xf02(%rip),%rdx
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
lea    0xef6(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf02(%rip),%rsi
mov    $0x0,%al
call   1030 <outputf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_set_destructor>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedd(%rip),%rsi
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xeea(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xeeb(%rip),%rsi
lea    0xf17(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xf09(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <outputf@plt>
lea    0xf16(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <outputf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.opctx = type { i32 }
@.str = [27 x i8] c"\09/* Set the destructor */\0A\00"
@.str.1 = [20 x i8] c"\09duk_dup(ctx, %d);\0A\00"
@.str.2 = [51 x i8] c"\09duk_push_c_function(ctx, %s_%s___destructor, 1);\0A\00"
@.str.3 = [6 x i8] c"dukky\00"
@.str.4 = [30 x i8] c"\09duk_set_finalizer(ctx, -2);\0A\00"
@.str.5 = [17 x i8] c"\09duk_pop(ctx);\0A\0A\00"
define i32 @output_set_destructor(%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 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.opctx*, %struct.opctx** %4
%10 = load i32, i32* %6
%11 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load %struct.opctx*, %struct.opctx** %4
%13 = load i8*, i8** %5
%14 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %12, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load %struct.opctx*, %struct.opctx** %4
%16 = call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %15, i8* getelementptr inbounds ([30 x i8], [30 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 ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.opctx = type { i32 }
@.str = [27 x i8] c"\09/* Set the destructor */\0A\00"
@.str.1 = [20 x i8] c"\09duk_dup(ctx, %d);\0A\00"
@.str.2 = [51 x i8] c"\09duk_push_c_function(ctx, %s_%s___destructor, 1);\0A\00"
@.str.3 = [6 x i8] c"dukky\00"
@.str.4 = [30 x i8] c"\09duk_set_finalizer(ctx, -2);\0A\00"
@.str.5 = [17 x i8] c"\09duk_pop(ctx);\0A\0A\00"
define i32 @output_set_destructor(%struct.opctx* %0, i8* %1, i32 %2) {
%4 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%6 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%7 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 (%struct.opctx*, i8*, ...) @outputf(%struct.opctx* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}