#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 csub(int);
int fwrapper(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int arg, cres, fres;
  printf("Welcome to GNU libtool mixed C/Fortran demo!\n");
  arg = 2;
  cres = csub(arg);
  printf("The C subroutine returned, claiming that 2*%d = %d\n", arg, cres);
  if (cres == 2 * arg)
    printf("The C subroutine is ok!\n");
  printf("\nCalling the C wrapper routine...\n");
  fres = fwrapper(arg);
  printf("The C wrapper to the fortran subroutine returned,\n"
         "claiming that 2*%d = %d\n",
         arg, fres);
  if (fres == 2 * arg)
    printf("The Fortran subroutine is ok!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <csub@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jne    1192 <main+0x62>
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1040 <fwrapper@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jne    11de <main+0xae>
lea    0xf12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xf37(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1060 <csub@plt>
mov    %eax,%ebx
lea    0xea0(%rip),%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x4,%ebx
jne    117f <main+0x3f>
lea    0xf72(%rip),%rdi
call   1030 <puts@plt>
lea    0xf26(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1050 <fwrapper@plt>
mov    %eax,%ebx
lea    0xe96(%rip),%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x4,%ebx
jne    11bd <main+0x7d>
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Welcome to GNU libtool mixed C/Fortran demo!\0A\00"
@.str.1 = [52 x i8] c"The C subroutine returned, claiming that 2*%d = %d\0A\00"
@.str.2 = [25 x i8] c"The C subroutine is ok!\0A\00"
@.str.3 = [35 x i8] c"\0ACalling the C wrapper routine...\0A\00"
@.str.4 = [75 x i8] c"The C wrapper to the fortran subroutine returned,\0Aclaiming that 2*%d = %d\0A\00"
@.str.5 = [31 x i8] c"The Fortran subroutine is ok!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @csub(i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = mul nsw i32 2, %12
%14 = icmp eq i32 %11, %13
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = call i32 @fwrapper(i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* %2
%26 = mul nsw i32 2, %25
%27 = icmp eq i32 %24, %26
br i1 %27, label %28, label %30
28: ; preds = %17
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %17
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [52 x i8] c"The C subroutine returned, claiming that 2*%d = %d\0A\00"
@.str.4 = [75 x i8] c"The C wrapper to the fortran subroutine returned,\0Aclaiming that 2*%d = %d\0A\00"
@str = [45 x i8] c"Welcome to GNU libtool mixed C/Fortran demo!\00"
@str.6 = [34 x i8] c"\0ACalling the C wrapper routine...\00"
@str.7 = [30 x i8] c"The Fortran subroutine is ok!\00"
@str.8 = [24 x i8] c"The C subroutine is ok!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @csub(i32 2)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %2)
%4 = icmp eq i32 %2, 4
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @fwrapper(i32 2)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 2, i32 %9)
%11 = icmp eq i32 %9, 4
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
br label %14
14: ; preds = %12, %7
ret i32 0
}