#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 /*<<< orphan*/ currTime();
int efWait(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getpid();
int parseId(char *);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printf(char *, long, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void waitForEventFlag(char *id) {
  int semId;
  semId = parseId(id);
  if (semId == -1) {
    fprintf(stderr, "Invalid event flag identifier: %s\n", id);
    return;
  }
  printf("[%ld][%s] %d: Waiting for flag to be set\n", (long)getpid(),
         currTime(), semId);
  if (efWait(semId) == -1)
    pexit("efWait");
  printf("[%ld][%s] %d: Flag is now set\n", (long)getpid(), currTime(), semId);
}


x86 assembly (clang, -O0):
<waitForEventFlag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <parseId@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b0 <waitForEventFlag+0x40>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1080 <fprintf@plt>
jmp    121b <waitForEventFlag+0xab>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <currTime@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
lea    0xe51(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <efWait@plt>
cmp    $0xffffffff,%eax
jne    11f4 <waitForEventFlag+0x84>
lea    0xe5e(%rip),%rdi
call   1090 <pexit@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <currTime@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
lea    0xe3e(%rip),%rdi
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForEventFlag>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <parseId@plt>
cmp    $0xffffffff,%eax
je     11e8 <waitForEventFlag+0x78>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <currTime@plt>
lea    0xe89(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
call   1060 <printf@plt>
mov    %ebp,%edi
call   1070 <efWait@plt>
cmp    $0xffffffff,%eax
jne    11be <waitForEventFlag+0x4e>
lea    0xe94(%rip),%rdi
call   1090 <pexit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <currTime@plt>
lea    0xe7e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <printf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Invalid event flag identifier: %s\0A\00"
@.str.1 = [42 x i8] c"[%ld][%s] %d: Waiting for flag to be set\0A\00"
@.str.2 = [7 x i8] c"efWait\00"
@.str.3 = [31 x i8] c"[%ld][%s] %d: Flag is now set\0A\00"
define void @waitForEventFlag(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @parseId(i8* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %27
12: ; preds = %1
%13 = call i64 (...) @getpid()
%14 = call i32 (...) @currTime()
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %13, i32 %14, i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @efWait(i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = call i64 (...) @getpid()
%24 = call i32 (...) @currTime()
%25 = load i32, i32* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %23, i32 %24, i32 %25)
br label %27
27: ; preds = %22, %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Invalid event flag identifier: %s\0A\00"
@.str.1 = [42 x i8] c"[%ld][%s] %d: Waiting for flag to be set\0A\00"
@.str.2 = [7 x i8] c"efWait\00"
@.str.3 = [31 x i8] c"[%ld][%s] %d: Flag is now set\0A\00"
define void @waitForEventFlag(i8* %0) {
%2 = tail call i32 @parseId(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
7: ; preds = %1
%8 = tail call i64 (...) @getpid()
%9 = tail call i32 (...) @currTime()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %8, i32 %9, i32 %2)
%11 = tail call i32 @efWait(i32 %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @pexit(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i64 (...) @getpid()
%17 = tail call i32 (...) @currTime()
%18 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %16, i32 %17, i32 %2)
br label %19
19: ; preds = %15, %4
ret void
}