#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int rand();
int nested_res(void) {
  int err = 0;
  uint8_t *foo_p = (uint8_t *)malloc(sizeof(uint8_t));
  if (foo_p == NULL) {
    err = 1;
  } else {
    int bar = rand();
    if (bar == 0) {
      err = 2;
    } else {
      int baz = rand();
      if (baz == 0) {
        err = 3;
      }
    }
    free(foo_p);
  }
  return err;
}


x86 assembly (clang, -O0):
<nested_res>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <nested_res+0x34>
movl   $0x1,-0x4(%rbp)
jmp    11ad <nested_res+0x7d>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1184 <nested_res+0x54>
movl   $0x2,-0x4(%rbp)
jmp    11a4 <nested_res+0x74>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    119f <nested_res+0x6f>
movl   $0x3,-0x4(%rbp)
jmp    11a4 <nested_res+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nested_res>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1163 <nested_res+0x33>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
test   %eax,%eax
je     116a <nested_res+0x3a>
xor    %eax,%eax
call   1050 <rand@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%ebp
jmp    116f <nested_res+0x3f>
mov    $0x1,%ebp
jmp    1177 <nested_res+0x47>
mov    $0x2,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @nested_res() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %14, label %4
4: ; preds = %0
%5 = tail call i32 (...) @rand()
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = tail call i32 (...) @rand()
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 3, i32 0
br label %11
11: ; preds = %4, %7
%12 = phi i32 [ %10, %7 ], [ 2, %4 ]
%13 = tail call i32 @free(i32* %2)
br label %14
14: ; preds = %0, %11
%15 = phi i32 [ %12, %11 ], [ 1, %0 ]
ret i32 %15
}