#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ do_get(struct sockaddr_in, char *);
int /*<<< orphan*/ do_help();
int /*<<< orphan*/ do_list(struct sockaddr_in);
int /*<<< orphan*/ do_put();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_in servaddr;
  char command[64];
  if (argc < 3) {
    printf("Usage : %s <ip> <port>\n", argv[0]);
    return -1;
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = PF_INET;
  servaddr.sin_port = htons(atoi(argv[2]));
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  while (1) {
    printf("client > ");
    fgets(command, 64, stdin);
    command[strlen(command) - 1] = '\0';
    if (strncmp(command, "help", 5) == 0) {
      do_help();
    } else if (strncmp(command, "quit", 5) == 0) {
      printf("bye\n");
      exit(0);
    } else if (strncmp(command, "list", 5) == 0) {
      do_list(servaddr);
    } else if (strncmp(command, "get", 3) == 0) {
      do_get(servaddr, command + 4);
    } else if (strncmp(command, "put", 3) == 0) {
      do_put();
    } else {
      printf("  wrong command : %s\n", command);
      do_help();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1216 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x80,%rsp
pop    %rbp
ret
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1090 <fgets@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ba <main+0xea>
mov    $0x0,%al
call   10b0 <do_help@plt>
jmp    13ca <main+0x1fa>
lea    -0x60(%rbp),%rdi
lea    0xd62(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ee <main+0x11e>
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x60(%rbp),%rdi
lea    0xd38(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    132c <main+0x15c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%esi
call   1080 <do_list@plt>
jmp    13c0 <main+0x1f0>
lea    -0x60(%rbp),%rdi
lea    0xcff(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1372 <main+0x1a2>
lea    -0x60(%rbp),%rdx
add    $0x4,%rdx
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%esi
call   10f0 <do_get@plt>
jmp    13bb <main+0x1eb>
lea    -0x60(%rbp),%rdi
lea    0xcbd(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    139d <main+0x1cd>
mov    $0x0,%al
call   1070 <do_put@plt>
jmp    13b6 <main+0x1e6>
lea    -0x60(%rbp),%rsi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10b0 <do_help@plt>
jmp    13bb <main+0x1eb>
jmp    13c0 <main+0x1f0>
jmp    13c5 <main+0x1f5>
jmp    13ca <main+0x1fa>
jmp    1257 <main+0x87>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     121b <main+0x3b>
mov    (%rbx),%rsi
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%r15d
mov    %r15d,0x8(%rsp)
mov    0x10(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    (%rsp),%r12
lea    0xdb6(%rip),%r13
mov    0x2d7f(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xdad(%rip),%rbp
jmp    128f <main+0xaf>
lea    0xdbb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   10c0 <do_help@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x40,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1288 <main+0xa8>
mov    %rbx,%rdi
lea    0xd50(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1375 <main+0x195>
mov    %rbx,%rdi
lea    0xd38(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1350 <main+0x170>
mov    %rbx,%rdi
lea    0xd24(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1360 <main+0x180>
mov    %rbx,%rdi
lea    0xd0f(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1277 <main+0x97>
xor    %eax,%eax
call   1080 <do_put@plt>
jmp    128f <main+0xaf>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r15d,%esi
call   1090 <do_list@plt>
jmp    128f <main+0xaf>
mov    %r12,%rdi
mov    %r15d,%esi
lea    0x14(%rsp),%rdx
call   1100 <do_get@plt>
jmp    128f <main+0xaf>
lea    0xcd3(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [24 x i8] c"Usage : %s <ip> <port>\0A\00"
@PF_INET = global i32 0
@.str.1 = [10 x i8] c"client > \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"bye\0A\00"
@.str.5 = [5 x i8] c"list\00"
@.str.6 = [4 x i8] c"get\00"
@.str.7 = [4 x i8] c"put\00"
@.str.8 = [22 x i8] c" wrong command : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca [64 x i8]
%8 = alloca { i64, i32 }
%9 = alloca { i64, i32 }
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15)
ret i32 -1
17: ; preds = %2
%18 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%19 = load i32, i32* @PF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
%25 = call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %25, i32* %26
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @inet_addr(i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
br label %33
33: ; preds = %17, %95
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 64, i32 %36)
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %33
%47 = call i32 (...) @do_help()
br label %95
48: ; preds = %33
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%50 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %48
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%57 = call i64 @strncmp(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %55
%60 = bitcast { i64, i32 }* %8 to i8*
%61 = bitcast %struct.sockaddr_in* %6 to i8*
%62 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 0
%63 = load i64, i64* %62
%64 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %8, i32 0, i32 1
%65 = load i32, i32* %64
%66 = call i32 @do_list(i64 %63, i32 %65)
br label %93
67: ; preds = %55
%68 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%69 = call i64 @strncmp(i8* %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %81
71: ; preds = %67
%72 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%73 = getelementptr inbounds i8, i8* %72, i64 4
%74 = bitcast { i64, i32 }* %9 to i8*
%75 = bitcast %struct.sockaddr_in* %6 to i8*
%76 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 0
%77 = load i64, i64* %76
%78 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 1
%79 = load i32, i32* %78
%80 = call i32 @do_get(i64 %77, i32 %79, i8* %73)
br label %92
81: ; preds = %67
%82 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%83 = call i64 @strncmp(i8* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 3)
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 (...) @do_put()
br label %91
87: ; preds = %81
%88 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = call i32 (...) @do_help()
br label %91
91: ; preds = %87, %85
br label %92
92: ; preds = %91, %71
br label %93
93: ; preds = %92, %59
br label %94
94: ; preds = %93
br label %95
95: ; preds = %94, %46
br label %33
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [24 x i8] c"Usage : %s <ip> <port>\0A\00"
@PF_INET = global i32 0
@.str.1 = [10 x i8] c"client > \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"help\00"
@.str.3 = [5 x i8] c"quit\00"
@.str.5 = [5 x i8] c"list\00"
@.str.6 = [4 x i8] c"get\00"
@.str.7 = [4 x i8] c"put\00"
@.str.8 = [22 x i8] c" wrong command : %s\0A\00"
@str = [4 x i8] c"bye\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [64 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
ret i32 -1
11: ; preds = %2
%12 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%13 = load i32, i32* @PF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = tail call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @inet_addr(i8* %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 4
%25 = bitcast %struct.sockaddr_in* %3 to i64*
%26 = load i64, i64* %25
br label %27
27: ; preds = %55, %11
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %6, i32 64, i32 %29)
%31 = call i32 @strlen(i8* %6)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 5)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %27
%38 = call i32 (...) @do_help()
br label %55
39: ; preds = %27
%40 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %39
%46 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 5)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @do_list(i64 %26, i32 %13)
br label %55
50: ; preds = %45
%51 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 3)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = call i32 @do_get(i64 %26, i32 %13, i8* %24)
br label %55
55: ; preds = %53, %61, %59, %48, %37
br label %27
56: ; preds = %50
%57 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 3)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (...) @do_put()
br label %55
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%63 = call i32 (...) @do_help()
br label %55
}