#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 SomeObject {
  int dummy;
};

/* Variables and functions */
double calculate_something(int, double);
double calculate_something_else(double, struct SomeObject *);
struct SomeObject *create_object(char *);
int error_code();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double);
int /*<<< orphan*/ free_object(struct SomeObject *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main() {
  double c, d;
  int errcode;
  struct SomeObject *objptr;
  c = calculate_something(42, 98.6);
  if ((errcode = error_code()) != 0) {
    fprintf(stderr, "error calculating something: %d\n", errcode);
    exit(1);
  }
  objptr = create_object("my object");
  d = calculate_something_else(c, objptr);
  free_object(objptr);
  fprintf(stdout, "calculated %f\n", d);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2a,%edi
movsd  0xe74(%rip),%xmm0
call   1080 <calculate_something@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <error_code@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11cd <main+0x5d>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
cvtsi2sdl -0x1c(%rbp),%xmm0
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe55(%rip),%rdi
call   1030 <create_object@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   1070 <calculate_something_else@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <free_object@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
movsd  -0x18(%rbp),%xmm0
lea    0xe25(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movsd  0xe83(%rip),%xmm0
mov    $0x2a,%edi
call   1080 <calculate_something@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <error_code@plt>
test   %eax,%eax
jne    11e5 <main+0x75>
lea    0xe8a(%rip),%rdi
call   1030 <create_object@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
mov    %rax,%rdi
call   1070 <calculate_something_else@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <free_object@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
movsd  0x8(%rsp),%xmm0
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2df4(%rip),%rcx
mov    (%rcx),%edi
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe0c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.SomeObject = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"error calculating something: %d\0A\00"
@.str.1 = [10 x i8] c"my object\00"
@stdout = global i32 0
@.str.2 = [15 x i8] c"calculated %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca %struct.SomeObject*
store i32 0, i32* %1
%6 = call double @calculate_something(i32 42, double 0x4058A66666666666)
store double %6, double* %2
%7 = call i32 (...) @error_code()
store i32 %7, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* %4
%12 = sitofp i32 %11 to double
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call %struct.SomeObject* @create_object(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store %struct.SomeObject* %16, %struct.SomeObject** %5
%17 = load double, double* %2
%18 = load %struct.SomeObject*, %struct.SomeObject** %5
%19 = call double @calculate_something_else(double %17, %struct.SomeObject* %18)
store double %19, double* %3
%20 = load %struct.SomeObject*, %struct.SomeObject** %5
%21 = call i32 @free_object(%struct.SomeObject* %20)
%22 = load i32, i32* @stdout
%23 = load double, double* %3
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.SomeObject = type { i32 }
@stderr = global i32 0
@.str = [33 x i8] c"error calculating something: %d\0A\00"
@.str.1 = [10 x i8] c"my object\00"
@stdout = global i32 0
@.str.2 = [15 x i8] c"calculated %f\0A\00"
define i32 @main() {
%1 = tail call double @calculate_something(i32 42, double 0x4058A66666666666)
%2 = tail call i32 (...) @error_code()
%3 = icmp eq i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = sitofp i32 %2 to double
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), double %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call %struct.SomeObject* @create_object(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call double @calculate_something_else(double %1, %struct.SomeObject* %10)
%12 = tail call i32 @free_object(%struct.SomeObject* %10)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), double %11)
%15 = tail call i32 @exit(i32 0)
unreachable
}