#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 getchar();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ping(int, char **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ start_receiver();
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(void) {
  puts("SmartUniversity - PingPong Example!");
  puts("================");
  printf("You are running Linux, MacOS, or FreeBSD?\n");
  puts("================");
  start_receiver();
  char cmd_buf[128];
  char cmd_ping[] = "ping";
  while (1) {
    puts("USAGE: ping [IP[%IF]]:");
    memset(cmd_buf, 0, 128);
    int cnt = 0;
    int lws = 0;
    int pos = 0;
    char *argv[2];
    int argc = 1;
    argv[0] = cmd_buf;
    argv[1] = NULL;
    while (cnt < 128) {
      int c = getchar();
      if (c == '\n' || c == '\r') {
        break;
      }
      if (c == ' ') {
        if (cnt > lws + 1) {
          cmd_buf[cnt] = 0;
          lws = cnt;
          pos = cnt + 1;
          ++argc;
        }
      } else {
        cmd_buf[cnt] = (char)c;
      }
      ++cnt;
    }
    if (strlen(cmd_buf) < 4 || strcmp(cmd_ping, cmd_buf) != 0 || argc > 2)
      continue;
    if (argc > 1) {
      argv[1] = cmd_buf + pos;
    }
    ping(argc, argv);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   10a0 <start_receiver@plt>
mov    0xe91(%rip),%eax
mov    %eax,-0x95(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0x91(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0xa0(%rbp)
movl   $0x0,-0xa4(%rbp)
movl   $0x1,-0xc4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movq   $0x0,-0xb8(%rbp)
cmpl   $0x80,-0x9c(%rbp)
jge    1309 <main+0x189>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0xa,-0xc8(%rbp)
je     1278 <main+0xf8>
cmpl   $0xd,-0xc8(%rbp)
jne    127d <main+0xfd>
jmp    1309 <main+0x189>
cmpl   $0x20,-0xc8(%rbp)
jne    12df <main+0x15f>
mov    -0x9c(%rbp),%eax
mov    -0xa0(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    12da <main+0x15a>
movslq -0x9c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x9c(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    12f5 <main+0x175>
mov    -0xc8(%rbp),%eax
mov    %al,%cl
movslq -0x9c(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1241 <main+0xc1>
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     1348 <main+0x1c8>
lea    -0x95(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1348 <main+0x1c8>
cmpl   $0x2,-0xc4(%rbp)
jle    134d <main+0x1cd>
jmp    11e1 <main+0x61>
cmpl   $0x1,-0xc4(%rbp)
jle    1372 <main+0x1f2>
lea    -0x90(%rbp),%rax
movslq -0xa4(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0xb8(%rbp)
mov    -0xc4(%rbp),%edi
lea    -0xc0(%rbp),%rsi
call   1090 <ping@plt>
jmp    11e1 <main+0x61>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    0xe90(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <start_receiver@plt>
movb   $0x0,0xc(%rsp)
movl   $0x676e6970,0x8(%rsp)
67
lea    0xe6f(%rip),%r14
lea    0x20(%rsp),%r13
jmp    11ec <main+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
lea    0x10(%rsp),%rsi
call   1080 <ping@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    %r13,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    $0x1,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    122d <main+0xbd>
add    $0x1,%r12
cmp    $0x80,%r12
je     1270 <main+0x100>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x20,%eax
je     1250 <main+0xe0>
cmp    $0xa,%eax
je     1270 <main+0x100>
cmp    $0xd,%eax
je     1270 <main+0x100>
mov    %al,0x20(%rsp,%r12,1)
jmp    1220 <main+0xb0>
nopw   0x0(%rax,%rax,1)
lea    0x1(%r15),%eax
cltq
cmp    %rax,%r12
jle    1220 <main+0xb0>
movb   $0x0,0x20(%rsp,%r12,1)
add    $0x1,%ebp
lea    0x1(%r12),%ebx
mov    %r12d,%r15d
jmp    1220 <main+0xb0>
xchg   %ax,%ax
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     11ec <main+0x7c>
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11ec <main+0x7c>
cmp    $0x2,%ebp
jg     11ec <main+0x7c>
jl     11e0 <main+0x70>
mov    %ebx,%eax
add    %rsp,%rax
add    $0x20,%rax
mov    %rax,0x18(%rsp)
jmp    11e0 <main+0x70>

LLVM IR (-O0):
@.str = [36 x i8] c"SmartUniversity - PingPong Example!\00"
@.str.1 = [17 x i8] c"================\00"
@.str.2 = [43 x i8] c"You are running Linux, MacOS, or FreeBSD?\0A\00"
@__const.main.cmd_ping = [5 x i8] c"ping\00"
@.str.3 = [23 x i8] c"USAGE: ping [IP[%IF]]:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i8*]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (...) @start_receiver()
%15 = bitcast [5 x i8]* %3 to i8*
br label %16
16: ; preds = %0, %73, %83
%17 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 128)
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 1, i32* %8
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
store i8* %20, i8** %21
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* null, i8** %22
br label %23
23: ; preds = %58, %16
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 128
br i1 %25, label %26, label %61
26: ; preds = %23
%27 = call i32 (...) @getchar()
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 10
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 13
br i1 %32, label %33, label %34
33: ; preds = %30, %26
br label %61
34: ; preds = %30
%35 = load i32, i32* %9
%36 = icmp eq i32 %35, 32
br i1 %36, label %37, label %52
37: ; preds = %34
%38 = load i32, i32* %4
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
%41 = icmp sgt i32 %38, %40
br i1 %41, label %42, label %51
42: ; preds = %37
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %4
store i32 %46, i32* %5
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %51
51: ; preds = %42, %37
br label %58
52: ; preds = %34
%53 = load i32, i32* %9
%54 = trunc i32 %53 to i8
%55 = load i32, i32* %4
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %52, %51
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %23
61: ; preds = %33, %23
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = icmp slt i32 %63, 4
br i1 %64, label %73, label %65
65: ; preds = %61
%66 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%68 = call i64 @strcmp(i8* %66, i8* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %73, label %70
70: ; preds = %65
%71 = load i32, i32* %8
%72 = icmp sgt i32 %71, 2
br i1 %72, label %73, label %74
73: ; preds = %70, %65, %61
br label %16
74: ; preds = %70
%75 = load i32, i32* %8
%76 = icmp sgt i32 %75, 1
br i1 %76, label %77, label %83
77: ; preds = %74
%78 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 1
store i8* %81, i8** %82
br label %83
83: ; preds = %77, %74
%84 = load i32, i32* %8
%85 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%86 = call i32 @ping(i32 %84, i8** %85)
br label %16
}

LLVM IR (-O2):
@.str = [36 x i8] c"SmartUniversity - PingPong Example!\00"
@.str.1 = [17 x i8] c"================\00"
@__const.main.cmd_ping = [5 x i8] c"ping\00"
@.str.3 = [23 x i8] c"USAGE: ping [IP[%IF]]:\00"
@str = [42 x i8] c"You are running Linux, MacOS, or FreeBSD?\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [5 x i8]
%3 = alloca [2 x i8*]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @start_receiver()
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%11 = bitcast [2 x i8*]* %3 to i8*
%12 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
br label %14
14: ; preds = %59, %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @memset(i8* %9, i32 0, i32 128)
store i8* %9, i8** %12
store i8* null, i8** %13
br label %17
17: ; preds = %14, %36
%18 = phi i64 [ 0, %14 ], [ %40, %36 ]
%19 = phi i32 [ 1, %14 ], [ %39, %36 ]
%20 = phi i32 [ 0, %14 ], [ %38, %36 ]
%21 = phi i32 [ 0, %14 ], [ %37, %36 ]
%22 = call i32 (...) @getchar()
switch i32 %22, label %33 [
i32 13, label %42
i32 10, label %42
i32 32, label %23
]
23: ; preds = %17
%24 = add nsw i32 %21, 1
%25 = sext i32 %24 to i64
%26 = icmp sgt i64 %18, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %18
store i8 0, i8* %28
%29 = add nsw i32 %19, 1
%30 = trunc i64 %18 to i32
%31 = add i32 %30, 1
%32 = trunc i64 %18 to i32
br label %36
33: ; preds = %17
%34 = trunc i32 %22 to i8
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %18
store i8 %34, i8* %35
br label %36
36: ; preds = %33, %27, %23
%37 = phi i32 [ %32, %27 ], [ %21, %23 ], [ %21, %33 ]
%38 = phi i32 [ %31, %27 ], [ %20, %23 ], [ %20, %33 ]
%39 = phi i32 [ %29, %27 ], [ %19, %23 ], [ %19, %33 ]
%40 = add nuw nsw i64 %18, 1
%41 = icmp eq i64 %40, 128
br i1 %41, label %42, label %17
42: ; preds = %17, %17, %36
%43 = phi i32 [ %20, %17 ], [ %20, %17 ], [ %38, %36 ]
%44 = phi i32 [ %19, %17 ], [ %19, %17 ], [ %39, %36 ]
%45 = call i32 @strlen(i8* %9)
%46 = icmp slt i32 %45, 4
br i1 %46, label %59, label %47
47: ; preds = %42
%48 = call i64 @strcmp(i8* %10, i8* %9)
%49 = icmp ne i64 %48, 0
%50 = icmp sgt i32 %44, 2
%51 = select i1 %49, i1 true, i1 %50
br i1 %51, label %59, label %52
52: ; preds = %47
%53 = icmp sgt i32 %44, 1
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = zext i32 %43 to i64
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %55
store i8* %56, i8** %13
br label %57
57: ; preds = %54, %52
%58 = call i32 @ping(i32 %44, i8** %12)
br label %59
59: ; preds = %42, %47, %57
br label %14
}