#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 do_something(int);
int test_ifelse2(int i) {
  int result = 0;
  if (!i)
    result = do_something(1);
  if (i == 1)
    result = do_something(1024);
  if (i == 2)
    result = do_something(2);
  if (i == 3)
    return do_something(8);
  if (i == 4)
    return do_something(2048);
  return result;
}


x86 assembly (clang, -O0):
<test_ifelse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1139 <test_ifelse2+0x29>
mov    $0x1,%edi
call   1030 <do_something@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1150 <test_ifelse2+0x40>
mov    $0x400,%edi
call   1030 <do_something@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1167 <test_ifelse2+0x57>
mov    $0x2,%edi
call   1030 <do_something@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1183 <test_ifelse2+0x73>
mov    $0x8,%edi
call   1030 <do_something@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <test_ifelse2+0x95>
cmpl   $0x4,-0x8(%rbp)
jne    119f <test_ifelse2+0x8f>
mov    $0x800,%edi
call   1030 <do_something@plt>
mov    %eax,-0x4(%rbp)
jmp    11a5 <test_ifelse2+0x95>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ifelse2>:
cmp    $0x4,%edi
ja     1127 <test_ifelse2+0x17>
movslq %edi,%rax
lea    0xee1(%rip),%rcx
mov    (%rcx,%rax,4),%edi
jmp    1030 <do_something@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @test_ifelse2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @do_something(i32 1)
store i32 %8, i32* %4
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @do_something(i32 1024)
store i32 %13, i32* %4
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @do_something(i32 2)
store i32 %18, i32* %4
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @do_something(i32 8)
store i32 %23, i32* %2
br label %31
24: ; preds = %19
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 4
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @do_something(i32 2048)
store i32 %28, i32* %2
br label %31
29: ; preds = %24
%30 = load i32, i32* %4
store i32 %30, i32* %2
br label %31
31: ; preds = %29, %27, %22
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@switch.table.test_ifelse2 = [5 x i32] [i32 1, i32 1024, i32 2, i32 8, i32 2048]
define i32 @test_ifelse2(i32 %0) {
%2 = icmp ult i32 %0, 5
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds [5 x i32], [5 x i32]* @switch.table.test_ifelse2, i64 0, i64 %4
%6 = load i32, i32* %5
%7 = tail call i32 @do_something(i32 %6)
br label %8
8: ; preds = %1, %3
%9 = phi i32 [ 0, %1 ], [ %7, %3 ]
ret i32 %9
}