#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 */
unsigned short count_sem_members(int);
int get_val_sem_member(int, unsigned short);
int /*<<< orphan*/ printf(char *, ...);
int display_sem(int semid) {
  unsigned short nsems, i;
  nsems = count_sem_members(semid);
  if (nsems < 0)
    return nsems;
  printf("%d: (%d)", semid, nsems);
  for (i = 0; i < nsems; i++) {
    int semval = get_val_sem_member(semid, i);
    printf("%d ", semval);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<display_sem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <count_sem_members@plt>
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
cmp    $0x0,%eax
jge    1160 <display_sem+0x30>
movzwl -0xa(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <display_sem+0xa1>
mov    -0x8(%rbp),%esi
movzwl -0xa(%rbp),%edx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movw   $0x0,-0xc(%rbp)
movzwl -0xc(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    11bc <display_sem+0x8c>
mov    -0x8(%rbp),%edi
movzwl -0xc(%rbp),%esi
call   1050 <get_val_sem_member@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xc(%rbp)
jmp    117b <display_sem+0x4b>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_sem>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
call   1040 <count_sem_members@plt>
mov    %eax,%ebp
movzwl %ax,%r14d
lea    0xea4(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14w,%r14w
je     119f <display_sem+0x5f>
lea    0xe93(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzwl %bx,%esi
mov    %r15d,%edi
call   1060 <get_val_sem_member@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    %bx,%bp
jne    1180 <display_sem+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d: (%d)\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @display_sem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i16
%5 = alloca i16
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call zeroext i16 @count_sem_members(i32 %7)
store i16 %8, i16* %4
%9 = load i16, i16* %4
%10 = zext i16 %9 to i32
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i16, i16* %4
%14 = zext i16 %13 to i32
store i32 %14, i32* %2
br label %37
15: ; preds = %1
%16 = load i32, i32* %3
%17 = load i16, i16* %4
%18 = zext i16 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
store i16 0, i16* %5
br label %20
20: ; preds = %32, %15
%21 = load i16, i16* %5
%22 = zext i16 %21 to i32
%23 = load i16, i16* %4
%24 = zext i16 %23 to i32
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = load i32, i32* %3
%28 = load i16, i16* %5
%29 = call i32 @get_val_sem_member(i32 %27, i16 zeroext %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %26
%33 = load i16, i16* %5
%34 = add i16 %33, 1
store i16 %34, i16* %5
br label %20
35: ; preds = %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %37
37: ; preds = %35, %12
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d: (%d)\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @display_sem(i32 %0) {
%2 = tail call zeroext i16 @count_sem_members(i32 %0)
%3 = zext i16 %2 to i32
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %3)
%5 = icmp eq i16 %2, 0
br i1 %5, label %12, label %6
6: ; preds = %1, %6
%7 = phi i16 [ %10, %6 ], [ 0, %1 ]
%8 = tail call i32 @get_val_sem_member(i32 %0, i16 zeroext %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = add nuw i16 %7, 1
%11 = icmp eq i16 %10, %2
br i1 %11, label %12, label %6
12: ; preds = %6, %1
%13 = tail call i32 @putchar(i32 10)
ret i32 0
}