#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*/ check_proc_at_index(int);
int /*<<< orphan*/ exit(int);
int get_index_for_proc(char *);
int /*<<< orphan*/ get_proc_info(int, int *, int *, int *, char **);
int /*<<< orphan*/ init_memshare(char *, int /*<<< orphan*/,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  int send, rec, data_size, mode = 0, index, i;
  char dest_proc[20], *procptr;
  memset(dest_proc, '\0', 20);
  if (argc < 2) {
    print_usage();
    exit(2);
  }
  if (!strcmp(argv[1], "-l")) {
    if (argc != 2) {
      print_usage();
      exit(2);
    }
    mode = 1;
  } else if (!strcmp(argv[1], "-ld")) {
    if (argc != 3) {
      print_usage();
      exit(2);
    }
    mode = 2;
    strncpy(dest_proc, argv[2], (20 - 1));
  }
  if (mode == 0) {
    print_usage();
    exit(3);
  }
  init_memshare("memwatch", 0, 0);
  switch (mode) {
  case 2:
    if ((index = get_index_for_proc(dest_proc)) != -1) {
      get_proc_info(index, &send, &rec, &data_size, &procptr);
      printf("Index %2d %18s  Sent %2d  Received %2d, Data size of %2d\n",
             index, procptr, send, rec, data_size);
      exit(0);
    }
    printf("No such process %s\n", dest_proc);
    exit(1);
    break;
  case 1:
    for (i = 0; i < 20; i++) {
      if (check_proc_at_index(i)) {
        get_proc_info(i, &send, &rec, &data_size, &procptr);
        printf("Index %2d %18s  Sent %2d  Received %2d, Data size of %2d\n", i,
               procptr, send, rec, data_size);
      }
    }
    exit(0);
    break;
  default:
    break;
  }
  exit(2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11e8 <main+0x48>
mov    $0x0,%al
call   10b0 <print_usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe09(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    122c <main+0x8c>
cmpl   $0x2,-0x8(%rbp)
je     1220 <main+0x80>
mov    $0x0,%al
call   10b0 <print_usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x20(%rbp)
jmp    1286 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1281 <main+0xe1>
cmpl   $0x3,-0x8(%rbp)
je     1264 <main+0xc4>
mov    $0x0,%al
call   10b0 <print_usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x2,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x13,%edx
call   1030 <strncpy@plt>
jmp    1286 <main+0xe6>
cmpl   $0x0,-0x20(%rbp)
jne    12a1 <main+0x101>
mov    $0x0,%al
call   10b0 <print_usage@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
lea    0xd5f(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1090 <init_memshare@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
sub    $0x1,%eax
je     1346 <main+0x1a6>
jmp    12c5 <main+0x125>
mov    -0x4c(%rbp),%eax
sub    $0x2,%eax
jne    13ba <main+0x21a>
jmp    12d6 <main+0x136>
lea    -0x40(%rbp),%rdi
call   1040 <get_index_for_proc@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     132a <main+0x18a>
mov    -0x24(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1060 <get_proc_info@plt>
mov    -0x24(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x40(%rbp),%rsi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x14,-0x28(%rbp)
jge    13b3 <main+0x213>
mov    -0x28(%rbp),%edi
call   10c0 <check_proc_at_index@plt>
cmp    $0x0,%eax
je     13a0 <main+0x200>
mov    -0x28(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x48(%rbp),%r8
call   1060 <get_proc_info@plt>
mov    -0x28(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a5 <main+0x205>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    134d <main+0x1ad>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    13bf <main+0x21f>
mov    $0x2,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
cmp    $0x1,%ebp
jg     11da <main+0x3a>
xor    %eax,%eax
call   10b0 <print_usage@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rbx
lea    0xe1b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    127b <main+0xdb>
cmp    $0x2,%ebp
jne    11c9 <main+0x29>
lea    0xe06(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <init_memshare@plt>
lea    0x14(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0xdeb(%rip),%rbx
xor    %ebp,%ebp
jmp    123c <main+0x9c>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x14,%ebp
je     12e7 <main+0x147>
mov    %ebp,%edi
call   10c0 <check_proc_at_index@plt>
test   %eax,%eax
je     1230 <main+0x90>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1060 <get_proc_info@plt>
mov    0x18(%rsp),%rdx
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1230 <main+0x90>
lea    0xd81(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    12ee <main+0x14e>
cmp    $0x3,%ebp
jne    11c9 <main+0x29>
mov    0x10(%r14),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x13,%edx
call   1030 <strncpy@plt>
lea    0xd53(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <init_memshare@plt>
mov    %rbx,%rdi
call   1040 <get_index_for_proc@plt>
cmp    $0xffffffff,%eax
jne    12ff <main+0x15f>
lea    0xd79(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
call   10b0 <print_usage@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    %eax,%edi
call   1060 <get_proc_info@plt>
mov    0x18(%rsp),%rdx
mov    0x14(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    0xc(%rsp),%r9d
lea    0xcda(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-l\00"
@.str.1 = [4 x i8] c"-ld\00"
@.str.2 = [9 x i8] c"memwatch\00"
@.str.3 = [58 x i8] c"Index %2d %18s Sent %2d Received %2d, Data size of %2d\0A\00"
@.str.4 = [20 x i8] c"No such process %s\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [20 x i8]
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 20)
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (...) @print_usage()
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %21
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 2
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 (...) @print_usage()
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %27
store i32 1, i32* %9
br label %53
34: ; preds = %21
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %52, label %40
40: ; preds = %34
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 3
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 (...) @print_usage()
%45 = call i32 @exit(i32 2)
unreachable
46: ; preds = %40
store i32 2, i32* %9
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @strncpy(i8* %47, i8* %50, i32 19)
br label %52
52: ; preds = %46, %34
br label %53
53: ; preds = %52, %33
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 (...) @print_usage()
%58 = call i32 @exit(i32 3)
unreachable
59: ; preds = %53
%60 = call i32 @init_memshare(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
%61 = load i32, i32* %9
switch i32 %61, label %103 [
i32 2, label %62
i32 1, label %80
]
62: ; preds = %59
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%64 = call i32 @get_index_for_proc(i8* %63)
store i32 %64, i32* %10
%65 = icmp ne i32 %64, -1
br i1 %65, label %66, label %76
66: ; preds = %62
%67 = load i32, i32* %10
%68 = call i32 @get_proc_info(i32 %67, i32* %6, i32* %7, i32* %8, i8** %13)
%69 = load i32, i32* %10
%70 = load i8*, i8** %13
%71 = load i32, i32* %6
%72 = load i32, i32* %7
%73 = load i32, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %69, i8* %70, i32 %71, i32 %72, i32 %73)
%75 = call i32 @exit(i32 0)
unreachable
76: ; preds = %62
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %59
store i32 0, i32* %11
br label %81
81: ; preds = %98, %80
%82 = load i32, i32* %11
%83 = icmp slt i32 %82, 20
br i1 %83, label %84, label %101
84: ; preds = %81
%85 = load i32, i32* %11
%86 = call i32 @check_proc_at_index(i32 %85)
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %97
88: ; preds = %84
%89 = load i32, i32* %11
%90 = call i32 @get_proc_info(i32 %89, i32* %6, i32* %7, i32* %8, i8** %13)
%91 = load i32, i32* %11
%92 = load i8*, i8** %13
%93 = load i32, i32* %6
%94 = load i32, i32* %7
%95 = load i32, i32* %8
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %91, i8* %92, i32 %93, i32 %94, i32 %95)
br label %97
97: ; preds = %88, %84
br label %98
98: ; preds = %97
%99 = load i32, i32* %11
%100 = add nsw i32 %99, 1
store i32 %100, i32* %11
br label %81
101: ; preds = %81
%102 = call i32 @exit(i32 0)
unreachable
103: ; preds = %59
br label %104
104: ; preds = %103
%105 = call i32 @exit(i32 2)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"-l\00"
@.str.1 = [4 x i8] c"-ld\00"
@.str.2 = [9 x i8] c"memwatch\00"
@.str.3 = [58 x i8] c"Index %2d %18s Sent %2d Received %2d, Data size of %2d\0A\00"
@.str.4 = [20 x i8] c"No such process %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = bitcast i8** %7 to i8*
%13 = call i32 @memset(i8* %11, i8 signext 0, i32 20)
%14 = icmp slt i32 %0, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (...) @print_usage()
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = icmp eq i32 %0, 2
br i1 %24, label %39, label %25
25: ; preds = %23
%26 = call i32 (...) @print_usage()
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %18
%29 = call i32 @strcmp(i8* dereferenceable(1) %20, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = icmp eq i32 %0, 3
br i1 %32, label %41, label %33
33: ; preds = %31
%34 = call i32 (...) @print_usage()
%35 = call i32 @exit(i32 2)
unreachable
36: ; preds = %28
%37 = call i32 (...) @print_usage()
%38 = call i32 @exit(i32 3)
unreachable
39: ; preds = %23
%40 = call i32 @init_memshare(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
br label %59
41: ; preds = %31
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @strncpy(i8* %11, i8* %43, i32 19)
%45 = call i32 @init_memshare(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
%46 = call i32 @get_index_for_proc(i8* %11)
%47 = icmp eq i32 %46, -1
br i1 %47, label %56, label %48
48: ; preds = %41
%49 = call i32 @get_proc_info(i32 %46, i32* %3, i32* %4, i32* %5, i8** %7)
%50 = load i8*, i8** %7
%51 = load i32, i32* %3
%52 = load i32, i32* %4
%53 = load i32, i32* %5
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %46, i8* %50, i32 %51, i32 %52, i32 %53)
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %41
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %39, %70
%60 = phi i32 [ 0, %39 ], [ %71, %70 ]
%61 = call i32 @check_proc_at_index(i32 %60)
%62 = icmp eq i32 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %59
%64 = call i32 @get_proc_info(i32 %60, i32* %3, i32* %4, i32* %5, i8** %7)
%65 = load i8*, i8** %7
%66 = load i32, i32* %3
%67 = load i32, i32* %4
%68 = load i32, i32* %5
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32 %60, i8* %65, i32 %66, i32 %67, i32 %68)
br label %70
70: ; preds = %59, %63
%71 = add nuw nsw i32 %60, 1
%72 = icmp eq i32 %71, 20
br i1 %72, label %73, label %59
73: ; preds = %70
%74 = call i32 @exit(i32 0)
unreachable
}