#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 */
typedef int /*<<< orphan*/ time_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int inet_network(char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  int rv = 0, opt = 0;
  int srv_ip = 0, srv_port = 0, nparam = 0, loop_time = 0;
  char remote_host[128] = {0};
  time_t t1, t2;
  int serviceid = -1;
  while ((opt = getopt(argc, argv, "hn:l:v:s:p:")) > 0) {
    switch (opt) {
    case 'n':
      nparam = atoi(optarg);
      printf("nparam=%x\n", nparam);
      break;
    case 'l':
      loop_time = atoi(optarg);
      printf("loop_time=%x\n", loop_time);
      break;
    case 's':
      if (sprintf(remote_host, "%s", optarg)) {
        srv_ip = inet_network(remote_host);
        printf("srv_ip=%x\n", srv_ip);
      }
      break;
    case 'p':
      srv_port = atoi(optarg);
      printf("srv_port=%x\n", srv_port);
      break;
    case 'h':
    default:
      printf("Usage: [n <nparam>] [l <loop_time>] [s <remote_host>] [p "
             "<remote_port>]\n");
      exit(0);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
movl   $0xffffffff,-0xbc(%rbp)
ff ff ff
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe52(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1300 <main+0x190>
mov    -0x18(%rbp),%eax
add    $0xffffff98,%eax
mov    %eax,%ecx
mov    %rcx,-0xc8(%rbp)
sub    $0xb,%eax
ja     12e6 <main+0x176>
mov    -0xc8(%rbp),%rax
lea    0xdeb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd3(%rip),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fb <main+0x18b>
mov    0x2dab(%rip),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fb <main+0x18b>
lea    -0xb0(%rbp),%rdi
mov    0x2d7c(%rip),%rax
mov    (%rax),%rdx
lea    0xdcf(%rip),%rsi
call   1080 <sprintf@plt>
cmp    $0x0,%eax
je     12b4 <main+0x144>
lea    -0xb0(%rbp),%rdi
call   1030 <inet_network@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fb <main+0x18b>
mov    0x2d38(%rip),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fb <main+0x18b>
jmp    12e6 <main+0x176>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    11d0 <main+0x60>
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe69(%rip),%rdx
call   1070 <getopt@plt>
test   %eax,%eax
jle    128e <main+0x11e>
lea    0xe35(%rip),%r12
mov    0x2e26(%rip),%r13
lea    0xe47(%rip),%r15
mov    %rsp,%r14
nopl   0x0(%rax)
add    $0xffffff94,%eax
cmp    $0x7,%eax
ja     12a2 <main+0x132>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x0(%r13),%rdi
call   1080 <atoi@plt>
lea    0xe32(%rip),%rdi
jmp    1270 <main+0x100>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
call   1080 <atoi@plt>
lea    0xe30(%rip),%rdi
jmp    1270 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%rsi
mov    %r14,%rdi
call   1050 <stpcpy@plt>
cmp    %r14d,%eax
je     1279 <main+0x109>
mov    %r14,%rdi
call   1040 <inet_network@plt>
lea    0xdf5(%rip),%rdi
jmp    1270 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%rdi
call   1080 <atoi@plt>
lea    0xdbc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
test   %eax,%eax
jg     11e0 <main+0x70>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"hn:l:v:s:p:\00"
@optarg = global i8* null
@.str.1 = [11 x i8] c"nparam=%x\0A\00"
@.str.2 = [14 x i8] c"loop_time=%x\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [11 x i8] c"srv_ip=%x\0A\00"
@.str.5 = [13 x i8] c"srv_port=%x\0A\00"
@.str.6 = [73 x i8] c"Usage: [n <nparam>] [l <loop_time>] [s <remote_host>] [p <remote_port>]\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 [128 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%16 = bitcast [128 x i8]* %12 to i8*
store i32 -1, i32* %15
br label %17
17: ; preds = %54, %2
%18 = load i32, i32* %4
%19 = load i8**, i8*** %5
%20 = call i32 @getopt(i32 %18, i8** %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %20, i32* %7
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %55
22: ; preds = %17
%23 = load i32, i32* %7
switch i32 %23, label %51 [
i32 110, label %24
i32 108, label %29
i32 115, label %34
i32 112, label %45
i32 104, label %50
]
24: ; preds = %22
%25 = load i8*, i8** @optarg
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %54
29: ; preds = %22
%30 = load i8*, i8** @optarg
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %54
34: ; preds = %22
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%36 = load i8*, i8** @optarg
%37 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%41 = call i32 @inet_network(i8* %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %39, %34
br label %54
45: ; preds = %22
%46 = load i8*, i8** @optarg
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %9
%48 = load i32, i32* %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %48)
br label %54
50: ; preds = %22
br label %51
51: ; preds = %22, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %45, %44, %29, %24
br label %17
55: ; preds = %17
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"hn:l:v:s:p:\00"
@optarg = global i8* null
@.str.1 = [11 x i8] c"nparam=%x\0A\00"
@.str.2 = [14 x i8] c"loop_time=%x\0A\00"
@.str.4 = [11 x i8] c"srv_ip=%x\0A\00"
@.str.5 = [13 x i8] c"srv_port=%x\0A\00"
@str = [72 x i8] c"Usage: [n <nparam>] [l <loop_time>] [s <remote_host>] [p <remote_port>]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %39
7: ; preds = %2
%8 = ptrtoint [128 x i8]* %3 to i64
br label %9
9: ; preds = %7, %36
%10 = phi i32 [ %5, %7 ], [ %37, %36 ]
switch i32 %10, label %33 [
i32 110, label %11
i32 108, label %15
i32 115, label %19
i32 112, label %29
]
11: ; preds = %9
%12 = load i8*, i8** @optarg
%13 = call i32 @atoi(i8* %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %36
15: ; preds = %9
%16 = load i8*, i8** @optarg
%17 = call i32 @atoi(i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %36
19: ; preds = %9
%20 = load i8*, i8** @optarg
%21 = call i8* @stpcpy(i8* %4, i8* %20)
%22 = ptrtoint i8* %21 to i64
%23 = sub i64 %22, %8
%24 = trunc i64 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %19
%27 = call i32 @inet_network(i8* %4)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %36
29: ; preds = %9
%30 = load i8*, i8** @optarg
%31 = call i32 @atoi(i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %36
33: ; preds = %9
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str, i64 0, i64 0))
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %19, %26, %29, %15, %11
%37 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%38 = icmp sgt i32 %37, 0
br i1 %38, label %9, label %39
39: ; preds = %36, %2
ret i32 0
}