#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_num;
  int sem_op;
  scalar_t__ sem_flg;
};

/* Variables and functions */
int rand();
struct sembuf *identify_tool(int *n) {
  int x, y, sem;
  static struct sembuf sops[3];
  *n = rand() % 3 + 1;
  for (x = 0; x < *n; x++) {
    do {
      sem = rand() % 3;
      for (y = 0; y < x; y++) {
        if (sops[y].sem_num == sem) {
          sem = -1;
          break;
        }
      }
    } while (sem == -1);
    sops[x].sem_num = sem;
    if (sem == 1) {
      sops[x].sem_op = rand() % 2 + 1;
    } else {
      sops[x].sem_op = -1;
    }
    sops[x].sem_flg = 0;
  }
  sops[*n].sem_num = 3;
  sops[*n].sem_op = -1;
  sops[*n].sem_flg = 0;
  return sops;
}


x86 assembly (clang, -O0):
<identify_tool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    -0x8(%rbp),%rax
mov    %edx,(%rax)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jge    124d <identify_tool+0x13d>
jmp    114f <identify_tool+0x3f>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b0 <identify_tool+0xa0>
movslq -0x10(%rbp),%rcx
lea    0x2ec1(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    119d <identify_tool+0x8d>
movl   $0xffffffff,-0x14(%rbp)
jmp    11b0 <identify_tool+0xa0>
jmp    11a2 <identify_tool+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <identify_tool+0x58>
jmp    11b5 <identify_tool+0xa5>
cmpl   $0xffffffff,-0x14(%rbp)
je     114f <identify_tool+0x3f>
mov    -0x14(%rbp),%ecx
movslq -0xc(%rbp),%rdx
lea    0x2e73(%rip),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
cmpl   $0x1,-0x14(%rbp)
jne    120c <identify_tool+0xfc>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
movslq -0xc(%rbp),%rcx
lea    0x2e43(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    %edx,0x4(%rax)
jmp    1225 <identify_tool+0x115>
movslq -0xc(%rbp),%rcx
lea    0x2e29(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0xffffffff,0x4(%rax)
movslq -0xc(%rbp),%rcx
lea    0x2e10(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movq   $0x0,0x8(%rax)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <identify_tool+0x2b>
mov    -0x8(%rbp),%rax
movslq (%rax),%rcx
lea    0x2de5(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x3,(%rax)
mov    -0x8(%rbp),%rax
movslq (%rax),%rcx
lea    0x2dca(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0xffffffff,0x4(%rax)
mov    -0x8(%rbp),%rax
movslq (%rax),%rcx
lea    0x2dae(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
movq   $0x0,0x8(%rax)
lea    0x2d98(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<identify_tool>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%edx
sub    %ecx,%edx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,(%r14)
test   %edx,%edx
js     11f1 <identify_tool+0xe1>
lea    0x2ee7(%rip),%r15
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    1165 <identify_tool+0x55>
cmp    $0xffffffff,%eax
jne    11a1 <identify_tool+0x91>
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
test   %r12,%r12
je     1160 <identify_tool+0x50>
xor    %ecx,%ecx
xchg   %ax,%ax
cmp    %eax,(%rcx,%r15,1)
je     1165 <identify_tool+0x55>
add    $0x10,%rcx
cmp    %rcx,%rbx
jne    1190 <identify_tool+0x80>
jmp    1160 <identify_tool+0x50>
mov    %r12,%r13
shl    $0x4,%r13
mov    %eax,0x0(%r13,%r15,1)
mov    $0xffffffff,%ecx
cmp    $0x1,%eax
jne    11cf <identify_tool+0xbf>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
neg    %ecx
add    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%r13,%r15,1)
movq   $0x0,0x8(%r13,%r15,1)
add    $0x1,%r12
movslq (%r14),%rax
add    $0x10,%rbx
cmp    %rax,%r12
jl     1165 <identify_tool+0x55>
movslq %eax,%rcx
shl    $0x4,%rcx
lea    0x2e41(%rip),%rax
movl   $0x3,(%rcx,%rax,1)
movslq (%r14),%rcx
shl    $0x4,%rcx
movl   $0xffffffff,0x4(%rcx,%rax,1)
ff
movslq (%r14),%rcx
shl    $0x4,%rcx
movq   $0x0,0x8(%rcx,%rax,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@identify_tool.sops = internal global [3 x %struct.sembuf] zeroinitializer
define %struct.sembuf* @identify_tool(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = call i32 (...) @rand()
%7 = srem i32 %6, 3
%8 = add nsw i32 %7, 1
%9 = load i32*, i32** %2
store i32 %8, i32* %9
store i32 0, i32* %3
br label %10
10: ; preds = %66, %1
%11 = load i32, i32* %3
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %69
15: ; preds = %10
br label %16
16: ; preds = %37, %15
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 3
store i32 %18, i32* %5
store i32 0, i32* %4
br label %19
19: ; preds = %33, %16
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %25
%27 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* %5
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 -1, i32* %5
br label %36
32: ; preds = %23
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %19
36: ; preds = %31, %19
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, -1
br i1 %39, label %16, label %40
40: ; preds = %37
%41 = load i32, i32* %5
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %43
%45 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %44, i32 0, i32 0
store i32 %41, i32* %45
%46 = load i32, i32* %5
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %56
48: ; preds = %40
%49 = call i32 (...) @rand()
%50 = srem i32 %49, 2
%51 = add nsw i32 %50, 1
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %53
%55 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %54, i32 0, i32 1
store i32 %51, i32* %55
br label %61
56: ; preds = %40
%57 = load i32, i32* %3
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %58
%60 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %59, i32 0, i32 1
store i32 -1, i32* %60
br label %61
61: ; preds = %56, %48
%62 = load i32, i32* %3
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %63
%65 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %64, i32 0, i32 2
store i64 0, i64* %65
br label %66
66: ; preds = %61
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %10
69: ; preds = %10
%70 = load i32*, i32** %2
%71 = load i32, i32* %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %72
%74 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %73, i32 0, i32 0
store i32 3, i32* %74
%75 = load i32*, i32** %2
%76 = load i32, i32* %75
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %77
%79 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %78, i32 0, i32 1
store i32 -1, i32* %79
%80 = load i32*, i32** %2
%81 = load i32, i32* %80
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %82
%84 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %83, i32 0, i32 2
store i64 0, i64* %84
ret %struct.sembuf* getelementptr inbounds ([3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@identify_tool.sops = internal global [3 x %struct.sembuf] zeroinitializer
define %struct.sembuf* @identify_tool(i32* nocapture %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 3
%4 = add nsw i32 %3, 1
store i32 %4, i32* %0
%5 = icmp sgt i32 %3, -1
br i1 %5, label %6, label %38
6: ; preds = %1, %30
%7 = phi i64 [ %34, %30 ], [ 0, %1 ]
%8 = icmp eq i64 %7, 0
br label %9
9: ; preds = %22, %6
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 3
br i1 %8, label %20, label %14
12: ; preds = %14
%13 = icmp eq i64 %19, %7
br i1 %13, label %20, label %14
14: ; preds = %9, %12
%15 = phi i64 [ %19, %12 ], [ 0, %9 ]
%16 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %15, i32 0
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, %11
%19 = add nuw nsw i64 %15, 1
br i1 %18, label %22, label %12
20: ; preds = %12, %9
%21 = icmp eq i32 %11, -1
br i1 %21, label %22, label %23
22: ; preds = %14, %20
br label %9
23: ; preds = %20
%24 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %7, i32 0
store i32 %11, i32* %24
%25 = icmp eq i32 %11, 1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = tail call i32 (...) @rand()
%28 = srem i32 %27, 2
%29 = add nsw i32 %28, 1
br label %30
30: ; preds = %23, %26
%31 = phi i32 [ %29, %26 ], [ -1, %23 ]
%32 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %7, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %7, i32 2
store i64 0, i64* %33
%34 = add nuw nsw i64 %7, 1
%35 = load i32, i32* %0
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %6, label %38
38: ; preds = %30, %1
%39 = phi i32 [ %4, %1 ], [ %35, %30 ]
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %40, i32 0
store i32 3, i32* %41
%42 = load i32, i32* %0
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %43, i32 1
store i32 -1, i32* %44
%45 = load i32, i32* %0
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 %46, i32 2
store i64 0, i64* %47
ret %struct.sembuf* getelementptr inbounds ([3 x %struct.sembuf], [3 x %struct.sembuf]* @identify_tool.sops, i64 0, i64 0)
}