#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__ cst_fun1(int);
scalar_t__ cst_fun2(int);
int foo();
scalar_t__ pure_fun1(int);
scalar_t__ pure_fun2(int);
int xxx(void) {
  int i, k = foo(), x = 0;
  for (i = 0; i < 100; i++) {
    x += cst_fun1(k);
    x += pure_fun1(k);
    if (k) {
      x += cst_fun2(k);
      x += pure_fun2(k);
    }
  }
  return x;
}


x86 assembly (clang, -O0):
<xxx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <foo@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jge    11eb <xxx+0x9b>
mov    -0x8(%rbp),%edi
call   1070 <cst_fun1@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <pure_fun1@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11d8 <xxx+0x88>
mov    -0x8(%rbp),%edi
call   1040 <cst_fun2@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <pure_fun2@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    11dd <xxx+0x8d>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1170 <xxx+0x20>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxx>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <foo@plt>
mov    %eax,%r14d
mov    $0x64,%r15d
jmp    1176 <xxx+0x26>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r15d
je     11ad <xxx+0x5d>
mov    %r14d,%edi
call   1070 <cst_fun1@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r14d,%edi
call   1030 <pure_fun1@plt>
mov    %rax,%rbx
add    %ebp,%ebx
test   %r14d,%r14d
je     1170 <xxx+0x20>
mov    %r14d,%edi
call   1040 <cst_fun2@plt>
add    %eax,%ebx
mov    %r14d,%edi
call   1050 <pure_fun2@plt>
add    %ebx,%eax
mov    %eax,%ebx
jmp    1170 <xxx+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @xxx() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @foo()
store i32 %4, i32* %2
store i32 0, i32* %3
store i32 0, i32* %1
br label %5
5: ; preds = %37, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i64 @cst_fun1(i32 %9)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, %10
%14 = trunc i64 %13 to i32
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = call i64 @pure_fun1(i32 %15)
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %3
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %8
%24 = load i32, i32* %2
%25 = call i64 @cst_fun2(i32 %24)
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %3
%30 = load i32, i32* %2
%31 = call i64 @pure_fun2(i32 %30)
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %3
br label %36
36: ; preds = %23, %8
br label %37
37: ; preds = %36
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 1
store i32 %39, i32* %1
br label %5
40: ; preds = %5
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @xxx() {
%1 = tail call i32 (...) @foo()
%2 = icmp eq i32 %1, 0
br label %3
3: ; preds = %0, %19
%4 = phi i32 [ 0, %0 ], [ %20, %19 ]
%5 = phi i32 [ 0, %0 ], [ %21, %19 ]
%6 = tail call i64 @cst_fun1(i32 %1)
%7 = trunc i64 %6 to i32
%8 = add i32 %4, %7
%9 = tail call i64 @pure_fun1(i32 %1)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
br i1 %2, label %19, label %12
12: ; preds = %3
%13 = tail call i64 @cst_fun2(i32 %1)
%14 = trunc i64 %13 to i32
%15 = add i32 %11, %14
%16 = tail call i64 @pure_fun2(i32 %1)
%17 = trunc i64 %16 to i32
%18 = add i32 %15, %17
br label %19
19: ; preds = %3, %12
%20 = phi i32 [ %18, %12 ], [ %11, %3 ]
%21 = add nuw nsw i32 %5, 1
%22 = icmp eq i32 %21, 100
br i1 %22, label %23, label %3
23: ; preds = %19
ret i32 %20
}