#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 */
struct katcl_line {
  int dummy;
};

/* Variables and functions */
int arg_count_katcl(struct katcl_line *);
char *arg_string_katcl(struct katcl_line *, int);
struct katcl_line *create_name_rpc_katcl(char *);
int /*<<< orphan*/ destroy_rpc_katcl(struct katcl_line *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int send_rpc_katcl(struct katcl_line *, int, int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  struct katcl_line *l;
  int result, total, i;
  char *ptr;
  if (argc <= 2) {
    fprintf(stderr, "usage: %s server-ip[:server-port] command\n", argv[0]);
    fprintf(stderr, "example: %s localhost:7147 ?watchdog\n", argv[0]);
    return 1;
  }
  l = create_name_rpc_katcl(argv[1]);
  if (l == NULL) {
    fprintf(stderr, "unable to create client connection to server %s: %s\n",
            argv[1], strerror(errno));
    return 1;
  }
  result = send_rpc_katcl(l, 5000, 0x01 | 0x02 | 0x10, argv[2], NULL);
  printf("result of %s request is %d\n", argv[2], result);
  total = arg_count_katcl(l);
  printf("have %d arguments in reply\n", total);
  for (i = 0; i < total; i++) {
    ptr = arg_string_katcl(l, i);
    printf("reply[%d] is <%s>\n", i, ptr);
  }
  destroy_rpc_katcl(l);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11e8 <main+0x68>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fd <main+0x17d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <create_name_rpc_katcl@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124e <main+0xce>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fd <main+0x17d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    $0x1388,%esi
mov    $0x13,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <send_rpc_katcl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <arg_count_katcl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12ed <main+0x16d>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <arg_string_katcl@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12ae <main+0x12e>
mov    -0x18(%rbp),%rdi
call   10a0 <destroy_rpc_katcl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
cmp    $0x2,%edi
jg     11c2 <main+0x42>
mov    0x2e49(%rip),%rbx
mov    (%rbx),%edi
mov    (%r15),%rdx
lea    0xe5d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r15),%rdx
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    128b <main+0x10b>
mov    0x8(%r15),%rdi
call   1030 <create_name_rpc_katcl@plt>
test   %rax,%rax
je     125a <main+0xda>
mov    %rax,%r12
mov    0x10(%r15),%rcx
xor    %r14d,%r14d
mov    %rax,%rdi
mov    $0x1388,%esi
mov    $0x13,%edx
xor    %r8d,%r8d
call   1060 <send_rpc_katcl@plt>
mov    0x10(%r15),%rsi
lea    0xe88(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1080 <arg_count_katcl@plt>
mov    %eax,%ebp
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1250 <main+0xd0>
lea    0xe92(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r12,%rdi
mov    %ebx,%esi
call   1070 <arg_string_katcl@plt>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1230 <main+0xb0>
mov    %r12,%rdi
call   10a0 <destroy_rpc_katcl@plt>
jmp    1291 <main+0x111>
mov    0x2d7f(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r15),%rbp
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdd5(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"usage: %s server-ip[:server-port] command\0A\00"
@.str.1 = [38 x i8] c"example: %s localhost:7147 ?watchdog\0A\00"
@.str.2 = [53 x i8] c"unable to create client connection to server %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"result of %s request is %d\0A\00"
@.str.4 = [28 x i8] c"have %d arguments in reply\0A\00"
@.str.5 = [19 x i8] c"reply[%d] is <%s>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.katcl_line*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 2
br i1 %12, label %13, label %24
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 1, i32* %3
br label %71
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call %struct.katcl_line* @create_name_rpc_katcl(i8* %27)
store %struct.katcl_line* %28, %struct.katcl_line** %6
%29 = load %struct.katcl_line*, %struct.katcl_line** %6
%30 = icmp eq %struct.katcl_line* %29, null
br i1 %30, label %31, label %39
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %37)
store i32 1, i32* %3
br label %71
39: ; preds = %24
%40 = load %struct.katcl_line*, %struct.katcl_line** %6
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @send_rpc_katcl(%struct.katcl_line* %40, i32 5000, i32 19, i8* %43, i32* null)
store i32 %44, i32* %7
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %48)
%50 = load %struct.katcl_line*, %struct.katcl_line** %6
%51 = call i32 @arg_count_katcl(%struct.katcl_line* %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %52)
store i32 0, i32* %9
br label %54
54: ; preds = %65, %39
%55 = load i32, i32* %9
%56 = load i32, i32* %8
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load %struct.katcl_line*, %struct.katcl_line** %6
%60 = load i32, i32* %9
%61 = call i8* @arg_string_katcl(%struct.katcl_line* %59, i32 %60)
store i8* %61, i8** %10
%62 = load i32, i32* %9
%63 = load i8*, i8** %10
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %62, i8* %63)
br label %65
65: ; preds = %58
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %54
68: ; preds = %54
%69 = load %struct.katcl_line*, %struct.katcl_line** %6
%70 = call i32 @destroy_rpc_katcl(%struct.katcl_line* %69)
store i32 0, i32* %3
br label %71
71: ; preds = %68, %31, %13
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
@stderr = global i32 0
@.str = [43 x i8] c"usage: %s server-ip[:server-port] command\0A\00"
@.str.1 = [38 x i8] c"example: %s localhost:7147 ?watchdog\0A\00"
@.str.2 = [53 x i8] c"unable to create client connection to server %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"result of %s request is %d\0A\00"
@.str.4 = [28 x i8] c"have %d arguments in reply\0A\00"
@.str.5 = [19 x i8] c"reply[%d] is <%s>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %39
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call %struct.katcl_line* @create_name_rpc_katcl(i8* %13)
%15 = icmp eq %struct.katcl_line* %14, null
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %20)
br label %39
22: ; preds = %11
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @send_rpc_katcl(%struct.katcl_line* %14, i32 5000, i32 19, i8* %24, i32* null)
%26 = load i8*, i8** %23
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %26, i32 %25)
%28 = tail call i32 @arg_count_katcl(%struct.katcl_line* %14)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = icmp sgt i32 %28, 0
br i1 %30, label %31, label %37
31: ; preds = %22, %31
%32 = phi i32 [ %35, %31 ], [ 0, %22 ]
%33 = tail call i8* @arg_string_katcl(%struct.katcl_line* %14, i32 %32)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %32, i8* %33)
%35 = add nuw nsw i32 %32, 1
%36 = icmp eq i32 %35, %28
br i1 %36, label %37, label %31
37: ; preds = %31, %22
%38 = tail call i32 @destroy_rpc_katcl(%struct.katcl_line* %14)
br label %39
39: ; preds = %37, %16, %4
%40 = phi i32 [ 1, %4 ], [ 1, %16 ], [ 0, %37 ]
ret i32 %40
}