#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 */
struct sembuf {
  int sem_flg;
  int /*<<< orphan*/ sem_op;
  int /*<<< orphan*/ sem_num;
};

/* Variables and functions */
int IPC_NOWAIT;
int SEM_UNDO;
int semget(int, int, int /*<<< orphan*/);
scalar_t__ semop(int, struct sembuf *, int);
int islocked(void) {
  int semid;
  struct sembuf trylock[1] = {
      {.sem_num = 0, .sem_op = 0, .sem_flg = SEM_UNDO | IPC_NOWAIT},
  };
  semid = semget(0x6F326862, 1, 0);
  if (semid < 0)
    return 0;
  if (semop(semid, trylock, 1) < 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<islocked>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ec1(%rip),%rax
mov    (%rax),%eax
mov    0x2eb0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x6f326862,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1175 <islocked+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11a3 <islocked+0x83>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0x0,%rax
jge    119c <islocked+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <islocked+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<islocked>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ec4(%rip),%rax
mov    0x2eb5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
movq   $0x0,0x4(%rsp)
xor    %ebx,%ebx
mov    $0x6f326862,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <semget@plt>
test   %eax,%eax
js     1170 <islocked+0x50>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %rax,%rbx
shr    $0x3f,%rbx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@IPC_NOWAIT = global i32 0
define i32 @islocked() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1 x %struct.sembuf]
%4 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 0
%6 = load i32, i32* @SEM_UNDO
%7 = load i32, i32* @IPC_NOWAIT
%8 = or i32 %6, %7
store i32 %8, i32* %5
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 1
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %4, i32 0, i32 2
store i32 0, i32* %10
%11 = call i32 @semget(i32 1865574498, i32 1, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 0, i32* %1
br label %22
15: ; preds = %0
%16 = load i32, i32* %2
%17 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%18 = call i64 @semop(i32 %16, %struct.sembuf* %17, i32 1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %1
br label %22
21: ; preds = %15
store i32 0, i32* %1
br label %22
22: ; preds = %21, %20, %14
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@IPC_NOWAIT = global i32 0
define i32 @islocked() {
%1 = alloca [1 x %struct.sembuf]
%2 = bitcast [1 x %struct.sembuf]* %1 to i8*
%3 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 0
%4 = load i32, i32* @SEM_UNDO
%5 = load i32, i32* @IPC_NOWAIT
%6 = or i32 %5, %4
store i32 %6, i32* %3
%7 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 1
store i32 0, i32* %7
%8 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 2
store i32 0, i32* %8
%9 = tail call i32 @semget(i32 1865574498, i32 1, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %0
%12 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0
%13 = call i64 @semop(i32 %9, %struct.sembuf* %12, i32 1)
%14 = lshr i64 %13, 63
%15 = trunc i64 %14 to i32
br label %16
16: ; preds = %11, %0
%17 = phi i32 [ 0, %0 ], [ %15, %11 ]
ret i32 %17
}