#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 *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ping_tcp(char *, int, int, int);
int ping_udp(char *, int, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *hostname;
  int prog_num, vers_num, ret1, ret2, timeout = 21;
  if (argc != 4 && argc != 5) {
    fprintf(stderr,
            "Usage: %s <hostname> <program number> <version> <timeout>\n",
            argv[0]);
    exit(1);
  }
  if (argc == 5) {
    timeout = atoi(argv[4]);
  }
  hostname = argv[1];
  prog_num = atoi(argv[2]);
  vers_num = atoi(argv[3]);
  ret1 = ping_udp(hostname, prog_num, vers_num, timeout);
  ret2 = ping_tcp(hostname, prog_num, vers_num, timeout);
  return (ret1 + ret2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x15,-0x2c(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11a7 <main+0x57>
cmpl   $0x5,-0x8(%rbp)
je     11a7 <main+0x57>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x5,-0x8(%rbp)
jne    11c1 <main+0x71>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1040 <ping_udp@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1050 <ping_tcp@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x4,%eax
jne    11c3 <main+0x73>
mov    $0x15,%r14d
cmp    $0x5,%edi
jne    117c <main+0x2c>
mov    0x20(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r14d,%ecx
call   1040 <ping_udp@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1050 <ping_tcp@plt>
add    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2a(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [59 x i8] c"Usage: %s <hostname> <program number> <version> <timeout>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 21, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 5
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14, %2
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 4
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %11
br label %32
32: ; preds = %27, %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %7
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %8
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = load i32, i32* %11
%48 = call i32 @ping_udp(i8* %44, i32 %45, i32 %46, i32 %47)
store i32 %48, i32* %9
%49 = load i8*, i8** %6
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = load i32, i32* %11
%53 = call i32 @ping_tcp(i8* %49, i32 %50, i32 %51, i32 %52)
store i32 %53, i32* %10
%54 = load i32, i32* %9
%55 = load i32, i32* %10
%56 = add nsw i32 %54, %55
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [59 x i8] c"Usage: %s <hostname> <program number> <version> <timeout>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 4
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %0, 5
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = getelementptr inbounds i8*, i8** %1, i64 4
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
br label %16
16: ; preds = %12, %10
%17 = phi i32 [ %15, %12 ], [ 21, %10 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i32 @ping_udp(i8* %19, i32 %22, i32 %25, i32 %17)
%27 = tail call i32 @ping_tcp(i8* %19, i32 %22, i32 %25, i32 %17)
%28 = add nsw i32 %27, %26
ret i32 %28
}