#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sem_down(void *);
void *sem_get(int);
char *shm_get(int);
int stoi(char *);
void main_test_3_ipc(int argc, char **argv) {
  uint64_t key = stoi(argv[0]);
  void *sem = sem_get(key);
  char *shm = shm_get(key);
  printf("Semaforo %d bloqueado\n", key);
  sem_down(sem);
  printf("Semaforo %d desbloqueado, mensaje leido de shm %d: %s\n", key, key,
         shm);
}


x86 assembly (clang, -O0):
<main_test_3_ipc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <stoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <sem_get@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <shm_get@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <sem_down@plt>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_test_3_ipc>:
push   %r15
push   %r14
push   %rbx
mov    (%rsi),%rdi
call   1070 <stoi@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <sem_get@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <shm_get@plt>
mov    %rax,%r15
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <sem_down@plt>
lea    0xe85(%rip),%rdi
mov    %ebx,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Semaforo %d bloqueado\0A\00"
@.str.1 = [55 x i8] c"Semaforo %d desbloqueado, mensaje leido de shm %d: %s\0A\00"
define void @main_test_3_ipc(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @stoi(i8* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = call i8* @sem_get(i32 %12)
store i8* %13, i8** %6
%14 = load i32, i32* %5
%15 = call i8* @shm_get(i32 %14)
store i8* %15, i8** %7
%16 = load i32, i32* %5
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %6
%19 = call i32 @sem_down(i8* %18)
%20 = load i32, i32* %5
%21 = load i32, i32* %5
%22 = load i8*, i8** %7
%23 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21, i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Semaforo %d bloqueado\0A\00"
@.str.1 = [55 x i8] c"Semaforo %d desbloqueado, mensaje leido de shm %d: %s\0A\00"
define void @main_test_3_ipc(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @stoi(i8* %3)
%5 = tail call i8* @sem_get(i32 %4)
%6 = tail call i8* @shm_get(i32 %4)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = tail call i32 @sem_down(i8* %5)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %4, i8* %6)
ret void
}