#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 */
scalar_t__ i_am_const2(int);
scalar_t__ i_am_const3(int);
int i_am_pure1(int);
scalar_t__ i_am_pure4(int);
test() {
  int s;
  s = i_am_pure1(5);
  s += i_am_pure1(5);
  s += i_am_const2(5);
  s += i_am_const2(5);
  s += i_am_const3(5);
  s += i_am_const3(5);
  s += i_am_pure4(5);
  s += i_am_pure4(5);
  return s;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x5,%edi
call   1050 <i_am_pure1@plt>
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1050 <i_am_pure1@plt>
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1030 <i_am_const2@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1030 <i_am_const2@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1060 <i_am_const3@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1060 <i_am_const3@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1040 <i_am_pure4@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x5,%edi
call   1040 <i_am_pure4@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %rbx
push   %rax
mov    $0x5,%edi
call   1050 <i_am_pure1@plt>
mov    %eax,%ebx
mov    $0x5,%edi
call   1050 <i_am_pure1@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    $0x5,%edi
call   1030 <i_am_const2@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    $0x5,%edi
call   1030 <i_am_const2@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    $0x5,%edi
call   1060 <i_am_const3@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    $0x5,%edi
call   1060 <i_am_const3@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    $0x5,%edi
call   1040 <i_am_pure4@plt>
mov    %rax,%rbx
add    %ebp,%ebx
mov    $0x5,%edi
call   1040 <i_am_pure4@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test() {
%1 = alloca i32
%2 = call i32 @i_am_pure1(i32 5)
store i32 %2, i32* %1
%3 = call i32 @i_am_pure1(i32 5)
%4 = load i32, i32* %1
%5 = add nsw i32 %4, %3
store i32 %5, i32* %1
%6 = call i64 @i_am_const2(i32 5)
%7 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = add nsw i64 %8, %6
%10 = trunc i64 %9 to i32
store i32 %10, i32* %1
%11 = call i64 @i_am_const2(i32 5)
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = add nsw i64 %13, %11
%15 = trunc i64 %14 to i32
store i32 %15, i32* %1
%16 = call i64 @i_am_const3(i32 5)
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %1
%21 = call i64 @i_am_const3(i32 5)
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = add nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %1
%26 = call i64 @i_am_pure4(i32 5)
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %1
%31 = call i64 @i_am_pure4(i32 5)
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %1
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
define i32 @test() {
%1 = tail call i32 @i_am_pure1(i32 5)
%2 = tail call i32 @i_am_pure1(i32 5)
%3 = add nsw i32 %2, %1
%4 = tail call i64 @i_am_const2(i32 5)
%5 = trunc i64 %4 to i32
%6 = add i32 %3, %5
%7 = tail call i64 @i_am_const2(i32 5)
%8 = trunc i64 %7 to i32
%9 = add i32 %6, %8
%10 = tail call i64 @i_am_const3(i32 5)
%11 = trunc i64 %10 to i32
%12 = add i32 %9, %11
%13 = tail call i64 @i_am_const3(i32 5)
%14 = trunc i64 %13 to i32
%15 = add i32 %12, %14
%16 = tail call i64 @i_am_pure4(i32 5)
%17 = trunc i64 %16 to i32
%18 = add i32 %15, %17
%19 = tail call i64 @i_am_pure4(i32 5)
%20 = trunc i64 %19 to i32
%21 = add i32 %18, %20
ret i32 %21
}