#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 */
scalar_t__ _inetd(int, int, char const *);
int _usage();
int getopt(int, char **, char *);
char *optarg;
int optind;
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int o;
  int debug = 0;
  int queue = 128;
  char const *filename = "/etc/inetd.conf";
  char *p;
  while ((o = getopt(argc, argv, "dq")) != -1) {
    if (o == 'd')
      debug = 1;
    else if (o == 'q') {
      queue = strtol(optarg, &p, 10);
      if (*optarg == '\0' || *p != '\0')
        return _usage();
    } else
      return _usage();
  }
  if (argc - optind == 1)
    filename = argv[optind];
  else if (argc != optind)
    return _usage();
  return _inetd(debug, queue, filename) ? 2 : 0;
}


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   $0x0,-0x18(%rbp)
movl   $0x80,-0x1c(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe93(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     121c <main+0xdc>
cmpl   $0x64,-0x14(%rbp)
jne    11a4 <main+0x64>
movl   $0x1,-0x18(%rbp)
jmp    1217 <main+0xd7>
cmpl   $0x71,-0x14(%rbp)
jne    1203 <main+0xc3>
mov    0x2e43(%rip),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <main+0xaf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fe <main+0xbe>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x155>
jmp    1212 <main+0xd2>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x155>
jmp    1217 <main+0xd7>
jmp    116f <main+0x2f>
mov    -0x8(%rbp),%eax
mov    0x2dba(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jne    124c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x2da4(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
jmp    1272 <main+0x132>
mov    -0x8(%rbp),%eax
mov    0x2d8a(%rip),%rcx
cmp    (%rcx),%eax
je     126d <main+0x12d>
mov    $0x0,%al
call   1030 <_usage@plt>
mov    %eax,-0x4(%rbp)
jmp    1295 <main+0x155>
jmp    1272 <main+0x132>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <_inetd@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
mov    $0x80,%ebp
movl   $0x0,0xc(%rsp)
lea    0xea9(%rip),%r12
mov    0x2e8a(%rip),%r14
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <getopt@plt>
cmp    $0x71,%eax
jne    11b8 <main+0x78>
mov    (%r14),%rdi
mov    %r13,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
mov    (%r14),%rax
cmpb   $0x0,(%rax)
je     1216 <main+0xd6>
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     1180 <main+0x40>
jmp    1216 <main+0xd6>
cmp    $0xffffffff,%eax
je     11cc <main+0x8c>
cmp    $0x64,%eax
jne    1216 <main+0xd6>
movl   $0x1,0xc(%rsp)
jmp    1180 <main+0x40>
mov    0x2e0d(%rip),%rax
movslq (%rax),%rax
mov    %ebx,%ecx
sub    %eax,%ecx
cmp    $0x1,%ecx
jne    11e5 <main+0xa5>
mov    (%r15,%rax,8),%rdx
jmp    11f0 <main+0xb0>
cmp    %ebx,%eax
jne    1216 <main+0xd6>
lea    0xe10(%rip),%rdx
mov    0xc(%rsp),%edi
mov    %ebp,%esi
call   1040 <_inetd@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
add    %ecx,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_usage@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/etc/inetd.conf\00"
@.str.1 = [3 x i8] c"dq\00"
@optarg = global i8* null
@optind = global i32 0
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 i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 128, i32* %8
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %9
br label %11
11: ; preds = %41, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 100
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 1, i32* %7
br label %41
20: ; preds = %16
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 113
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i8*, i8** @optarg
%25 = call i32 @strtol(i8* %24, i8** %10, i32 10)
store i32 %25, i32* %8
%26 = load i8*, i8** @optarg
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30, %23
%36 = call i32 (...) @_usage()
store i32 %36, i32* %3
br label %68
37: ; preds = %30
br label %40
38: ; preds = %20
%39 = call i32 (...) @_usage()
store i32 %39, i32* %3
br label %68
40: ; preds = %37
br label %41
41: ; preds = %40, %19
br label %11
42: ; preds = %11
%43 = load i32, i32* %4
%44 = load i32, i32* @optind
%45 = sub nsw i32 %43, %44
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %53
47: ; preds = %42
%48 = load i8**, i8*** %5
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
store i8* %52, i8** %9
br label %60
53: ; preds = %42
%54 = load i32, i32* %4
%55 = load i32, i32* @optind
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (...) @_usage()
store i32 %58, i32* %3
br label %68
59: ; preds = %53
br label %60
60: ; preds = %59, %47
%61 = load i32, i32* %7
%62 = load i32, i32* %8
%63 = load i8*, i8** %9
%64 = call i64 @_inetd(i32 %61, i32 %62, i8* %63)
%65 = icmp ne i64 %64, 0
%66 = zext i1 %65 to i64
%67 = select i1 %65, i32 2, i32 0
store i32 %67, i32* %3
br label %68
68: ; preds = %60, %57, %38, %35
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [16 x i8] c"/etc/inetd.conf\00"
@.str.1 = [3 x i8] c"dq\00"
@optarg = global i8* null
@optind = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
br label %5
5: ; preds = %8, %2
%6 = phi i32 [ 0, %2 ], [ 1, %8 ]
%7 = phi i32 [ 128, %2 ], [ %9, %8 ]
br label %8
8: ; preds = %5, %17
%9 = phi i32 [ %13, %17 ], [ %7, %5 ]
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %10, label %23 [
i32 -1, label %25
i32 100, label %5
i32 113, label %11
]
11: ; preds = %8
%12 = load i8*, i8** @optarg
%13 = call i32 @strtol(i8* %12, i8** %3, i32 10)
%14 = load i8*, i8** @optarg
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %8, label %21
21: ; preds = %17, %11
%22 = tail call i32 (...) @_usage()
br label %42
23: ; preds = %8
%24 = tail call i32 (...) @_usage()
br label %42
25: ; preds = %8
%26 = load i32, i32* @optind
%27 = sub nsw i32 %0, %26
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = sext i32 %26 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
br label %37
33: ; preds = %25
%34 = icmp eq i32 %26, %0
br i1 %34, label %37, label %35
35: ; preds = %33
%36 = tail call i32 (...) @_usage()
br label %42
37: ; preds = %33, %29
%38 = phi i8* [ %32, %29 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %33 ]
%39 = tail call i64 @_inetd(i32 %6, i32 %9, i8* %38)
%40 = icmp eq i64 %39, 0
%41 = select i1 %40, i32 0, i32 2
br label %42
42: ; preds = %37, %35, %23, %21
%43 = phi i32 [ %22, %21 ], [ %24, %23 ], [ %41, %37 ], [ %36, %35 ]
ret i32 %43
}