#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 rand();
int plain_nores(void) {
  int err = 0;
  int foo = rand();
  if (foo == 0) {
    err = 1;
  }
  if (err == 0) {
    int bar = rand();
    if (bar == 0) {
      err = 2;
    }
  }
  if (err == 0) {
    int baz = rand();
    if (baz == 0) {
      err = 3;
    }
  }
  return err;
}


x86 assembly (clang, -O0):
<plain_nores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    113a <plain_nores+0x2a>
movl   $0x1,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1164 <plain_nores+0x54>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    115f <plain_nores+0x4f>
movl   $0x2,-0x4(%rbp)
jmp    1164 <plain_nores+0x54>
cmpl   $0x0,-0x4(%rbp)
jne    118e <plain_nores+0x7e>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1189 <plain_nores+0x79>
movl   $0x3,-0x4(%rbp)
jmp    118e <plain_nores+0x7e>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plain_nores>:
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
test   %eax,%eax
je     113a <plain_nores+0x2a>
xor    %eax,%eax
call   1030 <rand@plt>
test   %eax,%eax
je     1141 <plain_nores+0x31>
xor    %eax,%eax
call   1030 <rand@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret
mov    $0x2,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @plain_nores() {
%1 = tail call i32 (...) @rand()
%2 = icmp eq i32 %1, 0
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 (...) @rand()
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 (...) @rand()
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 3, i32 0
br label %10
10: ; preds = %3, %0, %6
%11 = phi i32 [ %9, %6 ], [ 1, %0 ], [ 2, %3 ]
ret i32 %11
}