#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 pid_t;

/* Variables and functions */
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ semP(int);
int /*<<< orphan*/ semV(int);
int semcreate(int);
int main() {
  int semid1 = semcreate(4);
  int semid2;
  pid_t pid = getpid();
  semid2 = semcreate(42);
  semP(semid1);
  unsigned int i = 0;
  while (1) {
    semP(semid2);
    for (i = 0; i < 0x005FFFFE; i++) {
    }
    printf("%d:Ping?\n", pid);
    semV(semid1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1070 <semcreate@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x2a,%edi
call   1070 <semcreate@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <semP@plt>
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <semP@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x5ffffe,-0x14(%rbp)
jae    11c1 <main+0x71>
jmp    11b3 <main+0x63>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <main+0x51>
mov    -0x10(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <semV@plt>
jmp    1192 <main+0x42>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4,%edi
call   1070 <semcreate@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
mov    $0x2a,%edi
call   1070 <semcreate@plt>
mov    %eax,%ebx
mov    %r14d,%edi
call   1050 <semP@plt>
lea    0xe78(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <semP@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1060 <semV@plt>
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [10 x i8] c"%d:Ping?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @semcreate(i32 4)
store i32 %6, i32* %2
%7 = call i32 (...) @getpid()
store i32 %7, i32* %4
%8 = call i32 @semcreate(i32 42)
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = call i32 @semP(i32 %9)
store i32 0, i32* %5
br label %11
11: ; preds = %0, %21
%12 = load i32, i32* %3
%13 = call i32 @semP(i32 %12)
store i32 0, i32* %5
br label %14
14: ; preds = %18, %11
%15 = load i32, i32* %5
%16 = icmp ult i32 %15, 6291454
br i1 %16, label %17, label %21
17: ; preds = %14
br label %18
18: ; preds = %17
%19 = load i32, i32* %5
%20 = add i32 %19, 1
store i32 %20, i32* %5
br label %14
21: ; preds = %14
%22 = load i32, i32* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @semV(i32 %24)
br label %11
}

LLVM IR (-O2):
@.str = [10 x i8] c"%d:Ping?\0A\00"
define i32 @main() {
%1 = tail call i32 @semcreate(i32 4)
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @semcreate(i32 42)
%4 = tail call i32 @semP(i32 %1)
br label %5
5: ; preds = %5, %0
%6 = tail call i32 @semP(i32 %3)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%8 = tail call i32 @semV(i32 %1)
br label %5
}