#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*/ bar();
int /*<<< orphan*/ foo();
void fold_for(int a, int b) {
  for (int i = 0; a && i < b; ++i)
    foo();
  for (int i = 0; a || i < b; ++i)
    bar();
}


x86 assembly (clang, -O0):
<fold_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x11(%rbp)
je     1150 <fold_for+0x30>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1160 <fold_for+0x40>
jmp    1175 <fold_for+0x55>
mov    $0x0,%al
call   1040 <foo@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <fold_for+0x15>
movl   $0x0,-0x10(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x12(%rbp)
jne    1197 <fold_for+0x77>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11a7 <fold_for+0x87>
jmp    11bc <fold_for+0x9c>
mov    $0x0,%al
call   1030 <bar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <fold_for+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fold_for>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
test   %edi,%edi
je     114e <fold_for+0x2e>
test   %ebx,%ebx
jle    114e <fold_for+0x2e>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <foo@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
jl     1140 <fold_for+0x20>
test   %r14d,%r14d
jne    1157 <fold_for+0x37>
test   %ebx,%ebx
jle    1175 <fold_for+0x55>
mov    $0x1,%eax
nopl   0x0(%rax)
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <bar@plt>
lea    0x1(%rbp),%eax
test   %r14d,%r14d
jne    1160 <fold_for+0x40>
cmp    %ebx,%ebp
jl     1160 <fold_for+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @fold_for(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %18, %2
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = call i32 (...) @foo()
br label %18
18: ; preds = %16
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %7
21: ; preds = %14
store i32 0, i32* %6
br label %22
22: ; preds = %33, %21
%23 = load i32, i32* %3
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br label %29
29: ; preds = %25, %22
%30 = phi i1 [ true, %22 ], [ %28, %25 ]
br i1 %30, label %31, label %36
31: ; preds = %29
%32 = call i32 (...) @bar()
br label %33
33: ; preds = %31
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %22
36: ; preds = %29
ret void
}

LLVM IR (-O2):
define void @fold_for(i32 %0, i32 %1) {
%3 = icmp ne i32 %0, 0
%4 = icmp sgt i32 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %8, %2
%7 = or i1 %3, %4
br i1 %7, label %14, label %13
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = tail call i32 (...) @foo()
%11 = add nuw nsw i32 %9, 1
%12 = icmp slt i32 %11, %1
br i1 %12, label %8, label %6
13: ; preds = %14, %6
ret void
14: ; preds = %6, %14
%15 = phi i32 [ %17, %14 ], [ 0, %6 ]
%16 = tail call i32 (...) @bar()
%17 = add nuw nsw i32 %15, 1
%18 = icmp slt i32 %17, %1
%19 = select i1 %3, i1 true, i1 %18
br i1 %19, label %14, label %13
}