#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 plain_res(void) {
  int err = 0;
  uint8_t *foo_p = (uint8_t *)malloc(sizeof(uint8_t));
  if (foo_p == NULL) {
    err = 1;
  }
  if (err == 0) {
    int bar = rand();
    if (bar == 0) {
      err = 2;
    }
  }
  if (err == 0) {
    int baz = rand();
    if (baz == 0) {
      err = 3;
    }
  }
  if (foo_p != NULL)
    free(foo_p);
  return err;
}


x86 assembly (clang, -O0):
<plain_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    115f <plain_res+0x2f>
movl   $0x1,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1189 <plain_res+0x59>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1184 <plain_res+0x54>
movl   $0x2,-0x4(%rbp)
jmp    1189 <plain_res+0x59>
cmpl   $0x0,-0x4(%rbp)
jne    11b3 <plain_res+0x83>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ae <plain_res+0x7e>
movl   $0x3,-0x4(%rbp)
jmp    11b3 <plain_res+0x83>
cmpq   $0x0,-0x10(%rbp)
je     11c7 <plain_res+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plain_res>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1163 <plain_res+0x33>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <rand@plt>
test   %eax,%eax
je     116a <plain_res+0x3a>
xor    %eax,%eax
call   1050 <rand@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
lea    (%rcx,%rcx,2),%ebp
jmp    116f <plain_res+0x3f>
mov    $0x1,%ebp
jmp    1177 <plain_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 @plain_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 %10
10: ; preds = %9, %0
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = call i32 (...) @rand()
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 2, i32* %1
br label %18
18: ; preds = %17, %13
br label %19
19: ; preds = %18, %10
%20 = load i32, i32* %1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = call i32 (...) @rand()
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 3, i32* %1
br label %27
27: ; preds = %26, %22
br label %28
28: ; preds = %27, %19
%29 = load i32*, i32** %2
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32*, i32** %2
%33 = call i32 @free(i32* %32)
br label %34
34: ; preds = %31, %28
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
define i32 @plain_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
}