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

/* Variables and functions */
int IPC_CREAT;
int ftok(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int semget(int, int, int);
int /*<<< orphan*/ semop(int, struct sembuf *, int);
char *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(char *);
int shmget(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  int desc;
  int semid;
  char *sh;
  char s[128];
  struct sembuf sb;
  desc = ftok("pisos", 45);
  semid = semget(desc, 1, 0666 | IPC_CREAT);
  desc = shmget(desc, 256, 0);
  sh = shmat(desc, NULL, 0);
  sb.sem_op = -1;
  sb.sem_flg = 0;
  sb.sem_num = 0;
  semop(semid, &sb, 1);
  strncpy(s, sh + 4, *((int *)sh));
  printf("%s", s);
  shmdt(sh);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x2d,%esi
call   10a0 <ftok@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x100,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0xb8(%rbp)
ff ff ff
movq   $0x0,-0xa8(%rbp)
movq   $0x0,-0xb0(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xb8(%rbp),%rsi
mov    $0x1,%edx
call   1090 <semop@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1040 <strncpy@plt>
lea    -0xa0(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <shmdt@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0xa8,%rsp
lea    0xe70(%rip),%rdi
mov    $0x2d,%esi
call   10a0 <ftok@plt>
mov    %eax,%ebx
mov    0x2e3d(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0x100,%esi
xor    %edx,%edx
call   1080 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <shmat@plt>
mov    %rax,%rbx
movl   $0xffffffff,0x8(%rsp)
ff
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1090 <semop@plt>
lea    0x4(%rbx),%rsi
mov    (%rbx),%edx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strncpy@plt>
lea    0xdf7(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <shmdt@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@.str = [6 x i8] c"pisos\00"
@IPC_CREAT = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca %struct.sembuf
store i32 0, i32* %1
%7 = call i32 @ftok(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 45)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = load i32, i32* @IPC_CREAT
%10 = or i32 438, %9
%11 = call i32 @semget(i32 %8, i32 1, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = call i32 @shmget(i32 %12, i32 256, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i8* @shmat(i32 %14, i32* null, i32 0)
store i8* %15, i8** %4
%16 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 0
store i32 -1, i32* %16
%17 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 2
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i32 0, i32 1
store i64 0, i64* %18
%19 = load i32, i32* %3
%20 = call i32 @semop(i32 %19, %struct.sembuf* %6, i32 1)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 4
%24 = load i8*, i8** %4
%25 = bitcast i8* %24 to i32*
%26 = load i32, i32* %25
%27 = call i32 @strncpy(i8* %21, i8* %23, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %4
%31 = call i32 @shmdt(i8* %30)
ret i32 0
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@.str = [6 x i8] c"pisos\00"
@IPC_CREAT = global i32 0
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca %struct.sembuf
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sembuf* %2 to i8*
%5 = tail call i32 @ftok(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 45)
%6 = load i32, i32* @IPC_CREAT
%7 = or i32 %6, 438
%8 = tail call i32 @semget(i32 %5, i32 1, i32 %7)
%9 = tail call i32 @shmget(i32 %5, i32 256, i32 0)
%10 = tail call i8* @shmat(i32 %9, i32* null, i32 0)
%11 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 0
store i32 -1, i32* %11
%12 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
%13 = bitcast i64* %12 to i8*
%14 = call i32 @semop(i32 %8, %struct.sembuf* %2, i32 1)
%15 = getelementptr inbounds i8, i8* %10, i64 4
%16 = bitcast i8* %10 to i32*
%17 = load i32, i32* %16
%18 = call i32 @strncpy(i8* %3, i8* %15, i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%20 = call i32 @shmdt(i8* %10)
ret i32 0
}