#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*/ printf(char *, int);
int runfunc(int (*)(int), int);
int stub1(int);
int twice(int);
main() {
  int x, y;
  int (*f)(int);
  x = 3;
  y = twice(x);
  printf("result = %d\n", y);
  f = &twice;
  x = 4;
  y = (*f)(x);
  printf("result = %d\n", y);
  x = 5;
  y = runfunc(&twice, x);
  printf("result = %d\n", y);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <twice@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e90(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x4,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%edi
call   *%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x5,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    0x2e59(%rip),%rdi
call   1040 <runfunc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3,%edi
call   1050 <twice@plt>
mov    0x2eab(%rip),%r14
lea    0xec4(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x4,%edi
call   1050 <twice@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
call   1040 <runfunc@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"result = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32 (i32)*
store i32 3, i32* %1
%4 = load i32, i32* %1
%5 = call i32 @twice(i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 (i32)* @twice, i32 (i32)** %3
store i32 4, i32* %1
%8 = load i32 (i32)*, i32 (i32)** %3
%9 = load i32, i32* %1
%10 = call i32 %8(i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 5, i32* %1
%13 = load i32, i32* %1
%14 = call i32 @runfunc(i32 (i32)* @twice, i32 %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"result = %d\0A\00"
define i32 @main() {
%1 = tail call i32 @twice(i32 3)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @twice(i32 4)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @runfunc(i32 (i32)* @twice, i32 5)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
ret i32 0
}