#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_op;
  scalar_t__ sem_flg;
  scalar_t__ sem_num;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int semget(int, int, int);
int semop(int, struct sembuf *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int id;
  struct sembuf operations[1];
  int retval;
  id = semget((1492), 1, 0666);
  if (id < 0) {
    fprintf(stderr, "Semaforo nao localizado\n");
    exit(0);
  }
  operations[0].sem_num = 0;
  operations[0].sem_op = -1;
  operations[0].sem_flg = 0;
  retval = semop(id, operations, 1);
  if (retval == 0) {
    printf("Operacao P() executada com sucesso pelo Processo : %d \n",
           getpid());
  } else {
    printf("Falha em P()\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x5d4,%edi
mov    $0x1,%esi
mov    $0x1b6,%edx
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ac <main+0x4c>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1070 <semop@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11fd <main+0x9d>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120b <main+0xab>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    $0x5d4,%edi
mov    $0x1,%esi
mov    $0x1b6,%edx
call   1030 <semget@plt>
test   %eax,%eax
js     11da <main+0x6a>
movl   $0xffffffff,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
test   %eax,%eax
je     11bc <main+0x4c>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
jmp    11d3 <main+0x63>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
call   1070 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@stderr = global i32 0
@.str = [25 x i8] c"Semaforo nao localizado\0A\00"
@.str.1 = [56 x i8] c"Operacao P() executada com sucesso pelo Processo : %d \0A\00"
@.str.2 = [14 x i8] c"Falha em P()\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1 x %struct.sembuf]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @semget(i32 1492, i32 1, i32 438)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%14 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %13, i32 0, i32 2
store i64 0, i64* %14
%15 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%16 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %15, i32 0, i32 0
store i32 -1, i32* %16
%17 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%18 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %17, i32 0, i32 1
store i64 0, i64* %18
%19 = load i32, i32* %2
%20 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%21 = call i32 @semop(i32 %19, %struct.sembuf* %20, i32 1)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %12
%25 = call i32 (...) @getpid()
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %12
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
ret i32 0
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@stderr = global i32 0
@.str = [25 x i8] c"Semaforo nao localizado\0A\00"
@.str.1 = [56 x i8] c"Operacao P() executada com sucesso pelo Processo : %d \0A\00"
@str = [13 x i8] c"Falha em P()\00"
define i32 @main() {
%1 = alloca [1 x %struct.sembuf]
%2 = bitcast [1 x %struct.sembuf]* %1 to i8*
%3 = tail call i32 @semget(i32 1492, i32 1, i32 438)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0
%11 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 0
store i32 -1, i32* %11
%12 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 1
%13 = bitcast i64* %12 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %13
%14 = call i32 @semop(i32 %3, %struct.sembuf* %10, i32 1)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %9
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
ret i32 0
}