#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 atoi(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int tcpsock_connect(char *, int);
int main(int argc, char const *argv[]) {
  int port, sfd;
  char buf[128];
  if (argc < 2) {
    printf("Usage: ./client <port no>\n");
    exit(1);
  }
  port = atoi(argv[1]);
  sfd = tcpsock_connect("127.0.0.1", port);
  if (sfd < 0) {
    perror("tcp_connect() ");
    exit(1);
  }
  memset(buf, 0, 128);
  recv(sfd, buf, 128, 0);
  if (atoi(buf) == -1) {
    close(sfd);
    printf("Platform Busy !!\n");
    exit(1);
  }
  printf("Got %s\n", buf);
  while (1) {
    printf("Enter bogey seq (-1 to exit): ");
    memset(buf, 0, 128);
    scanf("%s", buf);
    if (atoi(buf) == -1) {
      send(sfd, "-1", 2, 0);
      close(sfd);
      break;
    }
    send(sfd, buf, strlen(buf), 0);
  }
  printf("Train Leaved Platform\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11eb <main+0x3b>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe16(%rip),%rdi
call   1040 <tcpsock_connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    122d <main+0x7d>
lea    0xe07(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0xa0(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0xdb>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xa0(%rbp),%rsi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0xa0(%rbp),%rdi
call   10c0 <atoi@plt>
cmp    $0xffffffff,%eax
jne    130c <main+0x15c>
mov    -0x18(%rbp),%edi
lea    0xd7d(%rip),%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    134a <main+0x19a>
mov    -0x18(%rbp),%eax
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xac(%rbp),%edi
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    12a0 <main+0xf0>
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
cmp    $0x1,%edi
jle    130f <main+0x14f>
mov    0x8(%rsi),%rdi
call   10d0 <atoi@plt>
lea    0xe1a(%rip),%rdi
mov    %eax,%esi
call   1040 <tcpsock_connect@plt>
test   %eax,%eax
js     1318 <main+0x158>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
cmp    $0xffffffff,%eax
je     132e <main+0x16e>
lea    0xde7(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
cmp    $0xffffffff,%eax
je     12d7 <main+0x117>
mov    %rsp,%rbx
lea    0xd9f(%rip),%r14
lea    0xdb7(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0xd0>
lea    0xd65(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0xd4c(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd57(%rip),%rdi
jmp    133c <main+0x17c>
lea    0xceb(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
lea    0xd20(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: ./client <port no>\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [15 x i8] c"tcp_connect() \00"
@.str.3 = [18 x i8] c"Platform Busy !!\0A\00"
@.str.4 = [8 x i8] c"Got %s\0A\00"
@.str.5 = [31 x i8] c"Enter bogey seq (-1 to exit): \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [3 x i8] c"-1\00"
@.str.8 = [23 x i8] c"Train Leaved Platform\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i32 @tcpsock_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %14
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 128)
%29 = load i32, i32* %7
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = call i32 @recv(i32 %29, i8* %30, i32 128, i32 0)
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%33 = call i32 @atoi(i8* %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %26
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %26
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %57
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 128)
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%50 = call i32 @atoi(i8* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %57
52: ; preds = %43
%53 = load i32, i32* %7
%54 = call i32 @send(i32 %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2, i32 0)
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
br label %63
57: ; preds = %43
%58 = load i32, i32* %7
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @send(i32 %58, i8* %59, i32 %61, i32 0)
br label %43
63: ; preds = %52
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [15 x i8] c"tcp_connect() \00"
@.str.4 = [8 x i8] c"Got %s\0A\00"
@.str.5 = [31 x i8] c"Enter bogey seq (-1 to exit): \00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [3 x i8] c"-1\00"
@str = [22 x i8] c"Train Leaved Platform\00"
@str.9 = [17 x i8] c"Platform Busy !!\00"
@str.10 = [26 x i8] c"Usage: ./client <port no>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 @tcpsock_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = call i32 @memset(i8* %4, i32 0, i32 128)
%20 = call i32 @recv(i32 %13, i8* %4, i32 128, i32 0)
%21 = call i32 @atoi(i8* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = call i32 @close(i32 %13)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 @memset(i8* %4, i32 0, i32 128)
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%32 = call i32 @atoi(i8* %4)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %38, %27
%35 = call i32 @send(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 2, i32 0)
%36 = call i32 @close(i32 %13)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
ret i32 0
38: ; preds = %27, %38
%39 = call i32 @strlen(i8* %4)
%40 = call i32 @send(i32 %13, i8* %4, i32 %39, i32 0)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @memset(i8* %4, i32 0, i32 128)
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%44 = call i32 @atoi(i8* %4)
%45 = icmp eq i32 %44, -1
br i1 %45, label %34, label %38
}