#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 */
char *AskForPlace(unsigned short *);
int DialServer(char *, unsigned short);
char *GetService(int, char *);
int /*<<< orphan*/ HangUp(int);
int /*<<< orphan*/ SendData(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_line(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
main() {
  char *machine, *text, *result;
  int connection;
  unsigned short port;
  machine = AskForPlace(&port);
  connection = DialServer(machine, port);
  if (machine)
    free(machine);
  if (!connection) {
    printf("no connection\n");
    exit(0);
  }
  while (1) {
    printf("input text (* to hang up and @ to kill server)\n");
    text = get_line(stdin);
    if (*text == '*' || *text == '@') {
      SendData(connection, text);
      HangUp(connection);
      free(text);
      exit(0);
    }
    result = GetService(connection, text);
    printf("type: %s\n", result);
    free(text);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x26(%rbp),%rdi
call   1040 <AskForPlace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movzwl -0x26(%rbp),%esi
call   1080 <DialServer@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d0 <main+0x40>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11ef <main+0x5f>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    11f4 <main+0x64>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1050 <get_line@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
je     1234 <main+0xa4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x40,%eax
jne    1258 <main+0xc8>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <SendData@plt>
mov    -0x24(%rbp),%edi
call   1060 <HangUp@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1090 <GetService@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11f4 <main+0x64>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe(%rsp),%rdi
call   1040 <AskForPlace@plt>
mov    %rax,%rbx
movzwl 0xe(%rsp),%esi
mov    %rax,%rdi
call   1090 <DialServer@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11d5 <main+0x35>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    11ec <main+0x4c>
lea    0xe2a(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xe25(%rip),%r14
mov    0x2dee(%rip),%r12
lea    0xdff(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <puts@plt>
mov    (%r12),%edi
call   1060 <get_line@plt>
mov    %rax,%rbx
movzbl (%rax),%eax
cmp    $0x40,%al
je     1250 <main+0xb0>
cmp    $0x2a,%al
je     1250 <main+0xb0>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10a0 <GetService@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1210 <main+0x70>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <SendData@plt>
mov    %ebp,%edi
call   1070 <HangUp@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"no connection\0A\00"
@.str.1 = [48 x i8] c"input text (* to hang up and @ to kill server)\0A\00"
@stdin = global i32 0
@.str.2 = [10 x i8] c"type: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16
store i32 0, i32* %1
%7 = call i8* @AskForPlace(i16* %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = load i16, i16* %6
%10 = call i32 @DialServer(i8* %8, i16 zeroext %9)
store i32 %10, i32* %5
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
br label %16
16: ; preds = %13, %0
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
br label %23
23: ; preds = %22, %45
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stdin
%26 = call i8* @get_line(i32 %25)
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 42
br i1 %30, label %36, label %31
31: ; preds = %23
%32 = load i8*, i8** %3
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 64
br i1 %35, label %36, label %45
36: ; preds = %31, %23
%37 = load i32, i32* %5
%38 = load i8*, i8** %3
%39 = call i32 @SendData(i32 %37, i8* %38)
%40 = load i32, i32* %5
%41 = call i32 @HangUp(i32 %40)
%42 = load i8*, i8** %3
%43 = call i32 @free(i8* %42)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %31
%46 = load i32, i32* %5
%47 = load i8*, i8** %3
%48 = call i8* @GetService(i32 %46, i8* %47)
store i8* %48, i8** %4
%49 = load i8*, i8** %4
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %3
%52 = call i32 @free(i8* %51)
br label %23
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.2 = [10 x i8] c"type: %s\0A\00"
@str = [14 x i8] c"no connection\00"
@str.3 = [47 x i8] c"input text (* to hang up and @ to kill server)\00"
define i32 @main() {
%1 = alloca i16
%2 = bitcast i16* %1 to i8*
%3 = call i8* @AskForPlace(i16* %1)
%4 = load i16, i16* %1
%5 = call i32 @DialServer(i8* %3, i16 zeroext %4)
%6 = icmp eq i8* %3, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @free(i8* %3)
br label %9
9: ; preds = %7, %0
%10 = icmp eq i32 %5, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %9, %24
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.3, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i8* @get_line(i32 %16)
%18 = load i8, i8* %17
switch i8 %18, label %24 [
i8 42, label %19
i8 64, label %19
]
19: ; preds = %14, %14
%20 = call i32 @SendData(i32 %5, i8* %17)
%21 = call i32 @HangUp(i32 %5)
%22 = call i32 @free(i8* %17)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %14
%25 = call i8* @GetService(i32 %5, i8* %17)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = call i32 @free(i8* %17)
br label %14
}