#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 /*<<< 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 Inexistente! Execute ./semabinit\n");
    exit(0);
  }
  printf("Inicio da operacao V ()\n");
  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 V () executada com sucesso\n");
  } else {
    printf("Erro em semop ()\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    119c <main+0x4c>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1060 <semop@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11ee <main+0x9e>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
jmp    11fa <main+0xaa>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    $0x5d4,%edi
mov    $0x1,%esi
mov    $0x1b6,%edx
call   1030 <semget@plt>
test   %eax,%eax
js     11ba <main+0x6a>
mov    %eax,%ebx
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <semop@plt>
test   %eax,%eax
lea    0xeb2(%rip),%rax
lea    0xe9a(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@stderr = global i32 0
@.str = [43 x i8] c"Semaforo Inexistente! Execute ./semabinit\0A\00"
@.str.1 = [25 x i8] c"Inicio da operacao V ()\0A\00"
@.str.2 = [37 x i8] c"Operacao V () executada com sucesso\0A\00"
@.str.3 = [18 x i8] c"Erro em semop ()\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 ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%15 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %14, i32 0, i32 2
store i64 0, i64* %15
%16 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%17 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %16, i32 0, i32 0
store i32 1, i32* %17
%18 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %18, i32 0, i32 1
store i64 0, i64* %19
%20 = load i32, i32* %2
%21 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%22 = call i32 @semop(i32 %20, %struct.sembuf* %21, i32 1)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %12
%26 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
br label %29
27: ; preds = %12
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
ret i32 0
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@stderr = global i32 0
@.str = [43 x i8] c"Semaforo Inexistente! Execute ./semabinit\0A\00"
@str = [24 x i8] c"Inicio da operacao V ()\00"
@str.4 = [17 x i8] c"Erro em semop ()\00"
@str.5 = [36 x i8] c"Operacao V () executada com sucesso\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 ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%11 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0
%12 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 0
store i32 1, i32* %12
%13 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %1, i64 0, i64 0, i32 1
%14 = bitcast i64* %13 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %14
%15 = call i32 @semop(i32 %3, %struct.sembuf* %11, i32 1)
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0)
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret i32 0
}