#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 /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ key_t;

/* Variables and functions */
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ delete_memory();
int /*<<< orphan*/ delete_processes_on_waiting();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ftok(char *, char);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmdt(int /*<<< orphan*/ *);
int shmget(int /*<<< orphan*/, int, int);
void kill_producer() {
  pid_t pid;
  key_t MyKey;
  int ShmID;
  pid_t *ShmPTR;
  char line[100], c;
  int i;
  MyKey = ftok(".", 's');
  ShmID = shmget(MyKey, sizeof(pid_t), 0666);
  ShmPTR = (pid_t *)shmat(ShmID, NULL, 0);
  pid = *ShmPTR;
  shmdt(ShmPTR);
  while (1) {
    printf("Presione k para matar el proceso > ");
    gets(line);
    for (i = 0; !(isalpha(line[i])); i++)
      ;
    c = line[i];
    if (c == 'k' || c == 'K') {
      printf("About to send a SIGQUIT signal\n");
      kill(pid, SIGQUIT);
      printf("Done.....\n");
      delete_memory();
      printf("\n");
      delete_processes_on_waiting();
      exit(0);
    } else
      printf("Wrong keypress (%c).  Try again\n", c);
  }
}


x86 assembly (clang, -O0):
<kill_producer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe3e(%rip),%rdi
mov    $0x73,%esi
call   10d0 <ftok@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
mov    $0x1b6,%edx
call   10b0 <shmget@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <shmat@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <shmdt@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1080 <gets@plt>
movl   $0x0,-0x88(%rbp)
movslq -0x88(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edi
call   1090 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124f <kill_producer+0x9f>
jmp    1268 <kill_producer+0xb8>
jmp    1254 <kill_producer+0xa4>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1229 <kill_producer+0x79>
movslq -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,1),%al
mov    %al,-0x81(%rbp)
movsbl -0x81(%rbp),%eax
cmp    $0x6b,%eax
je     1299 <kill_producer+0xe9>
movsbl -0x81(%rbp),%eax
cmp    $0x4b,%eax
jne    12e9 <kill_producer+0x139>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <delete_memory@plt>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <delete_processes_on_waiting@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
movsbl -0x81(%rbp),%esi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1208 <kill_producer+0x58>

x86 assembly (clang, -O2):
<kill_producer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xe89(%rip),%rdi
mov    $0x73,%esi
call   10f0 <ftok@plt>
mov    %eax,%edi
mov    $0x4,%esi
mov    $0x1b6,%edx
call   10d0 <shmget@plt>
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <shmat@plt>
mov    (%rax),%r14d
mov    %rax,%rdi
call   1050 <shmdt@plt>
lea    0xde5(%rip),%r15
mov    %rsp,%r12
lea    0xdff(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   10a0 <gets@plt>
mov    $0xffffffffffffffff,%rbp
nopl   0x0(%rax)
movsbl 0x1(%rsp,%rbp,1),%edi
call   10b0 <isalpha@plt>
add    $0x1,%rbp
test   %eax,%eax
je     1250 <kill_producer+0x80>
mov    %ebp,%eax
movsbl (%rsp,%rax,1),%esi
mov    %esi,%eax
and    $0xdf,%al
cmp    $0x4b,%al
je     127c <kill_producer+0xac>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1230 <kill_producer+0x60>
lea    0xdc2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1080 <kill@plt>
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <delete_memory@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <delete_processes_on_waiting@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [36 x i8] c"Presione k para matar el proceso > \00"
@.str.2 = [32 x i8] c"About to send a SIGQUIT signal\0A\00"
@SIGQUIT = global i32 0
@.str.3 = [11 x i8] c"Done.....\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [33 x i8] c"Wrong keypress (%c). Try again\0A\00"
define void @kill_producer() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [100 x i8]
%6 = alloca i8
%7 = alloca i32
%8 = call i32 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 115)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @shmget(i32 %9, i32 4, i32 438)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i64 @shmat(i32 %11, i32* null, i32 0)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = load i32, i32* %14
store i32 %15, i32* %1
%16 = load i32*, i32** %4
%17 = call i32 @shmdt(i32* %16)
br label %18
18: ; preds = %0, %60
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = call i32 @gets(i8* %20)
store i32 0, i32* %7
br label %22
22: ; preds = %31, %18
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @isalpha(i8 signext %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %34
30: ; preds = %22
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %22
34: ; preds = %22
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %6
%39 = load i8, i8* %6
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 107
br i1 %41, label %46, label %42
42: ; preds = %34
%43 = load i8, i8* %6
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 75
br i1 %45, label %46, label %56
46: ; preds = %42, %34
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %1
%49 = load i32, i32* @SIGQUIT
%50 = call i32 @kill(i32 %48, i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%52 = call i32 (...) @delete_memory()
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 (...) @delete_processes_on_waiting()
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %42
%57 = load i8, i8* %6
%58 = sext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %56
br label %18
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [36 x i8] c"Presione k para matar el proceso > \00"
@SIGQUIT = global i32 0
@.str.5 = [33 x i8] c"Wrong keypress (%c). Try again\0A\00"
@str = [31 x i8] c"About to send a SIGQUIT signal\00"
@str.6 = [10 x i8] c"Done.....\00"
define void @kill_producer() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @ftok(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 115)
%4 = tail call i32 @shmget(i32 %3, i32 4, i32 438)
%5 = tail call i64 @shmat(i32 %4, i32* null, i32 0)
%6 = inttoptr i64 %5 to i32*
%7 = load i32, i32* %6
%8 = tail call i32 @shmdt(i32* %6)
br label %9
9: ; preds = %34, %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @gets(i8* %2)
br label %12
12: ; preds = %12, %9
%13 = phi i64 [ %18, %12 ], [ 0, %9 ]
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = call i32 @isalpha(i8 signext %15)
%17 = icmp eq i32 %16, 0
%18 = add nuw i64 %13, 1
br i1 %17, label %12, label %19
19: ; preds = %12
%20 = and i64 %13, 4294967295
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = and i8 %22, -33
%24 = icmp eq i8 %23, 75
br i1 %24, label %25, label %34
25: ; preds = %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @SIGQUIT
%28 = call i32 @kill(i32 %7, i32 %27)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0))
%30 = call i32 (...) @delete_memory()
%31 = call i32 @putchar(i32 10)
%32 = call i32 (...) @delete_processes_on_waiting()
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %19
%35 = sext i8 %22 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %9
}