#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 */
char *crypt(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int ch;
  char *salt = "td";
  while ((ch = getopt(argc, argv, "hs:")) >= 0) {
    switch (ch) {
    default:
      fprintf(stderr, "Unknown Option '%c'\n", ch);
    case 'h':
      usage(argv[0]);
      return 0;
    case 's':
      salt = optarg;
      break;
    }
  }
  if (optind >= argc) {
    usage(argv[0]);
    return 1;
  }
  printf("#define TELNETD_DEFAULT_PASSWD \"%s\"\n", crypt(argv[optind], salt));
}


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)
lea    0xe93(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe84(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11f8 <main+0xa8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x68,%eax
je     11cd <main+0x7d>
jmp    11a4 <main+0x54>
mov    -0x24(%rbp),%eax
sub    $0x73,%eax
je     11e5 <main+0x95>
jmp    11b5 <main+0x65>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    124c <main+0xfc>
mov    0x2e0c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1171 <main+0x21>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1222 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x2db3(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <crypt@plt>
mov    %rax,%rsi
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%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,%r14
mov    %edi,%ebp
lea    0xe9f(%rip),%rdx
call   1070 <getopt@plt>
test   %eax,%eax
js     11c2 <main+0x72>
mov    0x2e84(%rip),%r12
lea    0xe88(%rip),%r15
nopl   0x0(%rax,%rax,1)
cmp    $0x73,%eax
jne    119c <main+0x4c>
mov    (%r12),%rbx
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <getopt@plt>
test   %eax,%eax
jns    1180 <main+0x30>
jmp    11c9 <main+0x79>
cmp    $0x68,%eax
je     11b8 <main+0x68>
mov    0x2e28(%rip),%rcx
mov    (%rcx),%edi
lea    0xe56(%rip),%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    (%r14),%rdi
call   1060 <usage@plt>
jmp    11f2 <main+0xa2>
lea    0xe37(%rip),%rbx
mov    0x2e10(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    11f6 <main+0xa6>
mov    (%r14,%rax,8),%rdi
mov    %rbx,%rsi
call   1030 <crypt@plt>
lea    0xe32(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1203 <main+0xb3>
mov    (%r14),%rdi
call   1060 <usage@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"td\00"
@.str.1 = [4 x i8] c"hs:\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Unknown Option '%c'\0A\00"
@optarg = global i8* null
@optind = global i32 0
@.str.3 = [37 x i8] c"#define TELNETD_DEFAULT_PASSWD \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %15 [
i32 104, label %19
i32 115, label %24
]
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = load i32, i32* %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %13, %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @usage(i8* %22)
store i32 0, i32* %3
br label %45
24: ; preds = %13
%25 = load i8*, i8** @optarg
store i8* %25, i8** %7
br label %26
26: ; preds = %24
br label %8
27: ; preds = %8
%28 = load i32, i32* @optind
%29 = load i32, i32* %4
%30 = icmp sge i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @usage(i8* %34)
store i32 1, i32* %3
br label %45
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = load i8*, i8** %7
%43 = call i8* @crypt(i8* %41, i8* %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %36, %31, %19
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"td\00"
@.str.1 = [4 x i8] c"hs:\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"Unknown Option '%c'\0A\00"
@optarg = global i8* null
@optind = global i32 0
@.str.3 = [37 x i8] c"#define TELNETD_DEFAULT_PASSWD \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %17
5: ; preds = %2, %13
%6 = phi i32 [ %15, %13 ], [ %3, %2 ]
switch i32 %6, label %7 [
i32 104, label %10
i32 115, label %13
]
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %10
10: ; preds = %5, %7
%11 = load i8*, i8** %1
%12 = tail call i32 @usage(i8* %11)
br label %30
13: ; preds = %5
%14 = load i8*, i8** @optarg
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp sgt i32 %15, -1
br i1 %16, label %5, label %17
17: ; preds = %13, %2
%18 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ], [ %14, %13 ]
%19 = load i32, i32* @optind
%20 = icmp slt i32 %19, %0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i8*, i8** %1
%23 = tail call i32 @usage(i8* %22)
br label %30
24: ; preds = %17
%25 = sext i32 %19 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i8* @crypt(i8* %27, i8* %18)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %24, %21, %10
%31 = phi i32 [ 0, %10 ], [ 1, %21 ], [ 0, %24 ]
ret i32 %31
}