#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 /*<<< orphan*/ sem_t;

/* Variables and functions */
int /*<<< orphan*/ sem_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ sem_unlink(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int destroy_sem(sem_t **s, int num) {
  int i;
  char sem_r[] = "semxxxx";
  char sem_n[256];
  for (i = 0; i < num; i++) {
    sem_close(s[i]);
    sprintf(sem_n, "%s%d", sem_r, i);
    sem_unlink(sem_n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<destroy_sem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a5 <destroy_sem+0x75>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <sem_close@plt>
lea    -0x120(%rbp),%rdi
lea    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe82(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <sem_unlink@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <destroy_sem+0x24>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<destroy_sem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movabs $0x787878786d6573,%rax
mov    %rax,0x8(%rsp)
test   %esi,%esi
jle    119a <destroy_sem+0x6a>
mov    %rdi,%r14
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0xe9e(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   0x0(%rax)
mov    (%r14,%rbx,8),%rdi
call   1030 <sem_close@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %ebx,%ecx
call   1040 <sprintf@plt>
mov    %r12,%rdi
call   1050 <sem_unlink@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <destroy_sem+0x40>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.destroy_sem.sem_r = [8 x i8] c"semxxxx\00"
@.str = [5 x i8] c"%s%d\00"
define i32 @destroy_sem(i32** %0, i32 %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca [256 x i8]
store i32** %0, i32*** %3
store i32 %1, i32* %4
%8 = bitcast [8 x i8]* %6 to i8*
store i32 0, i32* %5
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = load i32**, i32*** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32*, i32** %14, i64 %16
%18 = load i32*, i32** %17
%19 = call i32 @sem_close(i32* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @sem_unlink(i8* %24)
br label %26
26: ; preds = %13
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %9
29: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
define i32 @destroy_sem(i32** nocapture %0, i32 %1) {
%3 = alloca i64
%4 = alloca [256 x i8]
%5 = bitcast i64* %3 to i8*
store i64 33909456017122675, i64* %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %18, %10 ]
%12 = getelementptr inbounds i32*, i32** %0, i64 %11
%13 = load i32*, i32** %12
%14 = call i32 @sem_close(i32* %13)
%15 = trunc i64 %11 to i32
%16 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %15)
%17 = call i32 @sem_unlink(i8* %6)
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, %9
br i1 %19, label %20, label %10
20: ; preds = %10, %2
ret i32 0
}