#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*/ printf(char *);
void test_if(int i) {
  if (i == 1)
    printf("one");
  else if (i == 2)
    printf("two");
  else if (i == 3)
    printf("three");
  else
    printf("xxx");
  printf("\n");
}


x86 assembly (clang, -O0):
<test_if>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1136 <test_if+0x26>
lea    0xed4(%rip),%rdi
call   1030 <printf@plt>
jmp    1182 <test_if+0x72>
cmpl   $0x2,-0x4(%rbp)
jne    1151 <test_if+0x41>
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
jmp    117d <test_if+0x6d>
cmpl   $0x3,-0x4(%rbp)
jne    116c <test_if+0x5c>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1178 <test_if+0x68>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
jmp    117d <test_if+0x6d>
jmp    1182 <test_if+0x72>
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_if>:
push   %rax
add    $0xffffffff,%edi
cmp    $0x2,%edi
ja     113c <test_if+0x1c>
movslq %edi,%rax
lea    0xee1(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1143 <test_if+0x23>
lea    0xecb(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rax
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [6 x i8] c"three\00"
@.str.3 = [4 x i8] c"xxx\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @test_if(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %20
12: ; preds = %7
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
br label %20
20: ; preds = %19, %10
br label %21
21: ; preds = %20, %5
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [6 x i8] c"three\00"
@.str.3 = [4 x i8] c"xxx\00"
@reltable.test_if = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.test_if to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.test_if to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.test_if to i64)) to i32)]
define void @test_if(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 3
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.test_if to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %1 ]
%10 = tail call i32 @printf(i8* dereferenceable(1) %9)
%11 = tail call i32 @putchar(i32 10)
ret void
}