#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 */
scalar_t__ __VERIFIER_nondet_int();
int /*<<< orphan*/ lock();
int /*<<< orphan*/ unlock();
int main() {
  int got_lock;
  int old = 0, new = 0;
  if (__VERIFIER_nondet_int()) {
    do {
      got_lock = 0;
      if (__VERIFIER_nondet_int()) {
        lock();
        got_lock++;
      }
      if (got_lock) {
        unlock();
      }
    } while (__VERIFIER_nondet_int());
  }
  do {
    lock();
    old = new;
    if (__VERIFIER_nondet_int()) {
      unlock();
      new ++;
    }
  } while (new != old);
  unlock();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <__VERIFIER_nondet_int@plt>
cmp    $0x0,%rax
je     11b7 <main+0x87>
jmp    1163 <main+0x33>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <__VERIFIER_nondet_int@plt>
cmp    $0x0,%rax
je     118b <main+0x5b>
mov    $0x0,%al
call   1040 <lock@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     119c <main+0x6c>
mov    $0x0,%al
call   1030 <unlock@plt>
jmp    11a1 <main+0x71>
mov    $0x0,%al
call   1050 <__VERIFIER_nondet_int@plt>
cmp    $0x0,%rax
jne    1163 <main+0x33>
jmp    11b7 <main+0x87>
jmp    11bc <main+0x8c>
mov    $0x0,%al
call   1040 <lock@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <__VERIFIER_nondet_int@plt>
cmp    $0x0,%rax
je     11ea <main+0xba>
mov    $0x0,%al
call   1030 <unlock@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ef <main+0xbf>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11bc <main+0x8c>
mov    $0x0,%al
call   1030 <unlock@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <__VERIFIER_nondet_int@plt>
test   %rax,%rax
je     1177 <main+0x47>
xor    %eax,%eax
call   1050 <__VERIFIER_nondet_int@plt>
test   %rax,%rax
je     1140 <main+0x10>
xor    %eax,%eax
call   1040 <lock@plt>
xor    %eax,%eax
call   1030 <unlock@plt>
jmp    1140 <main+0x10>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <unlock@plt>
xor    %eax,%eax
call   1040 <lock@plt>
xor    %eax,%eax
call   1050 <__VERIFIER_nondet_int@plt>
test   %rax,%rax
jne    1170 <main+0x40>
xor    %eax,%eax
call   1030 <unlock@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i64 (...) @__VERIFIER_nondet_int()
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %0
br label %8
8: ; preds = %21, %7
store i32 0, i32* %2
%9 = call i64 (...) @__VERIFIER_nondet_int()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 (...) @lock()
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %15
15: ; preds = %11, %8
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (...) @unlock()
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20
%22 = call i64 (...) @__VERIFIER_nondet_int()
%23 = icmp ne i64 %22, 0
br i1 %23, label %8, label %24
24: ; preds = %21
br label %25
25: ; preds = %24, %0
br label %26
26: ; preds = %36, %25
%27 = call i32 (...) @lock()
%28 = load i32, i32* %4
store i32 %28, i32* %3
%29 = call i64 (...) @__VERIFIER_nondet_int()
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i32 (...) @unlock()
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %35
35: ; preds = %31, %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = icmp ne i32 %37, %38
br i1 %39, label %26, label %40
40: ; preds = %36
%41 = call i32 (...) @unlock()
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i64 (...) @__VERIFIER_nondet_int()
%2 = icmp eq i64 %1, 0
br i1 %2, label %12, label %3
3: ; preds = %0, %9
%4 = tail call i64 (...) @__VERIFIER_nondet_int()
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 (...) @lock()
%8 = tail call i32 (...) @unlock()
br label %9
9: ; preds = %3, %6
%10 = tail call i64 (...) @__VERIFIER_nondet_int()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %3
12: ; preds = %9, %0
%13 = tail call i32 (...) @lock()
%14 = tail call i64 (...) @__VERIFIER_nondet_int()
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %12, %16
%17 = tail call i32 (...) @unlock()
%18 = tail call i32 (...) @lock()
%19 = tail call i64 (...) @__VERIFIER_nondet_int()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %16
21: ; preds = %16, %12
%22 = tail call i32 (...) @unlock()
ret i32 0
}