void demo_foo2(int i) {
  if (i > 0) {
    printf("%s pos\n", __func__);
    if (0 == i % 2) {
      printf("%s even\n", __func__);
    } else {
      printf("%s odd\n", __func__);
    }
  } else if (i < 0) {
    printf("%s neg\n", __func__);
  } else {
    printf("%s zero\n", __func__);
  }
}


x86 assembly (clang, -O0):
<demo_foo2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1183 <demo_foo2+0x73>
lea    0xed4(%rip),%rdi
lea    0xed5(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    1169 <demo_foo2+0x59>
lea    0xebc(%rip),%rdi
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117e <demo_foo2+0x6e>
lea    0xeab(%rip),%rdi
lea    0xe91(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <demo_foo2+0xb1>
cmpl   $0x0,-0x4(%rbp)
jge    11a7 <demo_foo2+0x97>
lea    0xe8f(%rip),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <demo_foo2+0xac>
lea    0xe7d(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <demo_foo2+0xb1>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<demo_foo2>:
test   %edi,%edi
jle    1144 <demo_foo2+0x34>
push   %rbx
mov    %edi,%ebx
lea    0xee2(%rip),%rdi
lea    0xee3(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
test   $0x1,%bl
lea    0xedc(%rip),%rax
lea    0xede(%rip),%rdi
cmove  %rax,%rdi
pop    %rbx
jmp    1156 <demo_foo2+0x46>
lea    0xee0(%rip),%rax
lea    0xed1(%rip),%rdi
cmove  %rax,%rdi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%s pos\0A\00"
@__func__.demo_foo2 = [10 x i8] c"demo_foo2\00"
@.str.1 = [9 x i8] c"%s even\0A\00"
@.str.2 = [8 x i8] c"%s odd\0A\00"
@.str.3 = [8 x i8] c"%s neg\0A\00"
@.str.4 = [9 x i8] c"%s zero\0A\00"
define void @demo_foo2(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = srem i32 %7, 2
%9 = icmp eq i32 0, %8
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
br label %14
12: ; preds = %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
br label %23
15: ; preds = %1
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
br label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
br label %23
23: ; preds = %22, %14
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s pos\0A\00"
@__func__.demo_foo2 = [10 x i8] c"demo_foo2\00"
@.str.1 = [9 x i8] c"%s even\0A\00"
@.str.2 = [8 x i8] c"%s odd\0A\00"
@.str.3 = [8 x i8] c"%s neg\0A\00"
@.str.4 = [9 x i8] c"%s zero\0A\00"
define void @demo_foo2(i32 %0) {
%2 = icmp sgt i32 %0, 0
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
br label %11
8: ; preds = %1
%9 = icmp eq i32 %0, 0
%10 = select i1 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
br label %11
11: ; preds = %8, %3
%12 = phi i8* [ %7, %3 ], [ %10, %8 ]
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.demo_foo2, i64 0, i64 0))
ret void
}