#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 */
int /*<<< orphan*/ GETVAL;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int semctl(int, int, int /*<<< orphan*/, int /*<<< orphan*/);
int printPitStatus(int semid) {
  int i = 0, meat = -1, status = -1;
  printf("\n");
  for (i = 0; i < 3; i++) {
    if ((meat = semctl(semid, 2 * i + 1, GETVAL, 0)) == -1) {
      perror("Semctl(GETVAL) : ");
      return -1;
    }
    if ((status = semctl(semid, 2 * i, GETVAL, 0)) == -1) {
      perror("Semctl(GETVAL) : ");
      return -1;
    }
    printf("Pit %d has %d meat with status %d\n", i + 1, meat, status);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<printPitStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1214 <printPitStatus+0xe4>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
shl    $0x1,%esi
add    $0x1,%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1050 <semctl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11af <printPitStatus+0x7f>
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <printPitStatus+0xf9>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
shl    $0x1,%esi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1050 <semctl@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ec <printPitStatus+0xbc>
lea    0xe25(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <printPitStatus+0xf9>
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <printPitStatus+0x35>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printPitStatus>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2e89(%rip),%r14
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
mov    %eax,%ebp
mov    (%r14),%edx
mov    %ebx,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
lea    0xe81(%rip),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x3,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
mov    %eax,%ebp
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x2,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
lea    0xe38(%rip),%rdi
mov    $0x2,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%edx
mov    %ebx,%edi
mov    $0x5,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
mov    %eax,%ebp
mov    (%r14),%edx
xor    %r14d,%r14d
mov    %ebx,%edi
mov    $0x4,%esi
xor    %ecx,%ecx
call   1060 <semctl@plt>
cmp    $0xffffffff,%eax
je     123e <printPitStatus+0xfe>
lea    0xdf0(%rip),%rdi
mov    $0x3,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1250 <printPitStatus+0x110>
lea    0xdbb(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@GETVAL = global i32 0
@.str.1 = [18 x i8] c"Semctl(GETVAL) : \00"
@.str.2 = [35 x i8] c"Pit %d has %d meat with status %d\0A\00"
define i32 @printPitStatus(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 -1, i32* %5
store i32 -1, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %8
8: ; preds = %36, %1
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %39
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = mul nsw i32 2, %13
%15 = add nsw i32 %14, 1
%16 = load i32, i32* @GETVAL
%17 = call i32 @semctl(i32 %12, i32 %15, i32 %16, i32 0)
store i32 %17, i32* %5
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
21: ; preds = %11
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = mul nsw i32 2, %23
%25 = load i32, i32* @GETVAL
%26 = call i32 @semctl(i32 %22, i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %41
30: ; preds = %21
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %33, i32 %34)
br label %36
36: ; preds = %30
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %8
39: ; preds = %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %41
41: ; preds = %39, %28, %19
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@GETVAL = global i32 0
@.str.1 = [18 x i8] c"Semctl(GETVAL) : \00"
@.str.2 = [35 x i8] c"Pit %d has %d meat with status %d\0A\00"
define i32 @printPitStatus(i32 %0) {
%2 = tail call i32 @putchar(i32 10)
%3 = load i32, i32* @GETVAL
%4 = tail call i32 @semctl(i32 %0, i32 1, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %23, %14, %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %35
8: ; preds = %1
%9 = load i32, i32* @GETVAL
%10 = tail call i32 @semctl(i32 %0, i32 0, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %28, %19, %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %35
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %4, i32 %10)
%16 = load i32, i32* @GETVAL
%17 = tail call i32 @semctl(i32 %0, i32 3, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %6, label %19
19: ; preds = %14
%20 = load i32, i32* @GETVAL
%21 = tail call i32 @semctl(i32 %0, i32 2, i32 %20, i32 0)
%22 = icmp eq i32 %21, -1
br i1 %22, label %12, label %23
23: ; preds = %19
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %17, i32 %21)
%25 = load i32, i32* @GETVAL
%26 = tail call i32 @semctl(i32 %0, i32 5, i32 %25, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %6, label %28
28: ; preds = %23
%29 = load i32, i32* @GETVAL
%30 = tail call i32 @semctl(i32 %0, i32 4, i32 %29, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %12, label %32
32: ; preds = %28
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %26, i32 %30)
%34 = tail call i32 @putchar(i32 10)
br label %35
35: ; preds = %32, %12, %6
%36 = phi i32 [ -1, %6 ], [ -1, %12 ], [ 0, %32 ]
ret i32 %36
}