#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 */

/* Variables and functions */
int /*<<< orphan*/ attach_shared_memory();
int /*<<< orphan*/ detach_shared_memory();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_line(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *shmem_GetService(char *);
int /*<<< orphan*/ shmem_SendData(char *, char);
int /*<<< orphan*/ stdin;
main() {
  char *text, *result;
  attach_shared_memory();
  while (1) {
    printf("input text (* to hang up and @ to kill server)\n");
    text = get_line(stdin);
    if (*text == '*' || *text == '@') {
      shmem_SendData(text, '?');
      detach_shared_memory();
      free(text);
      exit(0);
    }
    result = shmem_GetService(text);
    printf("result: %s\n", result);
    free(text);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <attach_shared_memory@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1080 <get_line@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     11d6 <main+0x56>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    11fb <main+0x7b>
mov    -0x10(%rbp),%rdi
mov    $0x3f,%esi
call   1040 <shmem_SendData@plt>
mov    $0x0,%al
call   1070 <detach_shared_memory@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <shmem_GetService@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1196 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <attach_shared_memory@plt>
lea    0xe66(%rip),%r14
mov    0x2e3b(%rip),%r12
lea    0xe4c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <puts@plt>
mov    (%r12),%edi
call   1090 <get_line@plt>
mov    %rax,%rbx
movzbl (%rax),%eax
cmp    $0x40,%al
je     11fe <main+0x6e>
cmp    $0x2a,%al
je     11fe <main+0x6e>
mov    %rbx,%rdi
call   1070 <shmem_GetService@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11c0 <main+0x30>
mov    %rbx,%rdi
mov    $0x3f,%esi
call   1040 <shmem_SendData@plt>
xor    %eax,%eax
call   1080 <detach_shared_memory@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"input text (* to hang up and @ to kill server)\0A\00"
@stdin = global i32 0
@.str.1 = [12 x i8] c"result: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32 (...) @attach_shared_memory()
br label %5
5: ; preds = %0, %25
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i8* @get_line(i32 %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 42
br i1 %12, label %18, label %13
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 64
br i1 %17, label %18, label %25
18: ; preds = %13, %5
%19 = load i8*, i8** %2
%20 = call i32 @shmem_SendData(i8* %19, i8 signext 63)
%21 = call i32 (...) @detach_shared_memory()
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %13
%26 = load i8*, i8** %2
%27 = call i8* @shmem_GetService(i8* %26)
store i8* %27, i8** %3
%28 = load i8*, i8** %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
br label %5
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [12 x i8] c"result: %s\0A\00"
@str = [47 x i8] c"input text (* to hang up and @ to kill server)\00"
define i32 @main() {
%1 = tail call i32 (...) @attach_shared_memory()
br label %2
2: ; preds = %12, %0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = tail call i8* @get_line(i32 %4)
%6 = load i8, i8* %5
switch i8 %6, label %12 [
i8 42, label %7
i8 64, label %7
]
7: ; preds = %2, %2
%8 = tail call i32 @shmem_SendData(i8* %5, i8 signext 63)
%9 = tail call i32 (...) @detach_shared_memory()
%10 = tail call i32 @free(i8* %5)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = tail call i8* @shmem_GetService(i8* %5)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = tail call i32 @free(i8* %5)
br label %2
}