#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ suspend_allow(int);
int suspend_block(int);
int /*<<< orphan*/ suspend_close(int);
main(int argc, char *argv[]) {
  int sleep_time = 5;
  int handle;
  if (argc == 2)
    sleep_time = atoi(argv[1]);
  handle = suspend_block(-1);
  printf("Have the block - waiting\n");
  sleep(sleep_time);
  printf("Releasing...\n");
  suspend_allow(handle);
  sleep(1);
  handle = suspend_block(handle);
  printf("Blocked again\n");
  sleep(sleep_time);
  suspend_close(handle);
  printf("OK all done\n");
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x5,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11a7 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%edi
call   1050 <suspend_block@plt>
mov    %eax,-0x18(%rbp)
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <sleep@plt>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <suspend_allow@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x18(%rbp),%edi
call   1050 <suspend_block@plt>
mov    %eax,-0x18(%rbp)
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <sleep@plt>
mov    -0x18(%rbp),%edi
call   1030 <suspend_close@plt>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x5,%ebx
cmp    $0x2,%edi
jne    1188 <main+0x18>
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    $0xffffffff,%edi
call   1050 <suspend_block@plt>
mov    %eax,%ebp
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1090 <sleep@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <suspend_allow@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %ebp,%edi
call   1050 <suspend_block@plt>
mov    %eax,%ebp
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1090 <sleep@plt>
mov    %ebp,%edi
call   1040 <suspend_close@plt>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Have the block - waiting\0A\00"
@.str.1 = [14 x i8] c"Releasing...\0A\00"
@.str.2 = [15 x i8] c"Blocked again\0A\00"
@.str.3 = [13 x i8] c"OK all done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
br label %15
15: ; preds = %10, %2
%16 = call i32 @suspend_block(i32 -1)
store i32 %16, i32* %7
%17 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %6
%19 = call i32 @sleep(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* %7
%22 = call i32 @suspend_allow(i32 %21)
%23 = call i32 @sleep(i32 1)
%24 = load i32, i32* %7
%25 = call i32 @suspend_block(i32 %24)
store i32 %25, i32* %7
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %6
%28 = call i32 @sleep(i32 %27)
%29 = load i32, i32* %7
%30 = call i32 @suspend_close(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@str = [25 x i8] c"Have the block - waiting\00"
@str.4 = [13 x i8] c"Releasing...\00"
@str.5 = [14 x i8] c"Blocked again\00"
@str.6 = [12 x i8] c"OK all done\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ %7, %4 ], [ 5, %2 ]
%10 = tail call i32 @suspend_block(i32 -1)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @sleep(i32 %9)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @suspend_allow(i32 %10)
%15 = tail call i32 @sleep(i32 1)
%16 = tail call i32 @suspend_block(i32 %10)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
%18 = tail call i32 @sleep(i32 %9)
%19 = tail call i32 @suspend_close(i32 %16)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
}