#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 /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ digitstring(char *);
int help_rlogin(int, char **);
int open_remote(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int run_remote(int argc, char **argv) {
  if (!strcmp(argv[argc - 1], "?"))
    return help_rlogin(argc, argv);
  if (argc == 2) {
    if (!digitstring(argv[1])) {
      printf("Invalid port\n");
      return help_rlogin(argc, argv);
    }
    return open_remote(0, "127.0.0.1", atoi(argv[1]));
  } else if (argc == 3) {
    if (!digitstring(argv[2])) {
      printf("Invalid port\n");
      return help_rlogin(argc, argv);
    }
    return open_remote(0, argv[1], atoi(argv[2]));
  }
  return help_rlogin(argc, argv);
}


x86 assembly (clang, -O0):
<run_remote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe79(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11a9 <run_remote+0x49>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <help_rlogin@plt>
mov    %eax,-0x4(%rbp)
jmp    1290 <run_remote+0x130>
cmpl   $0x2,-0x8(%rbp)
jne    120e <run_remote+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <digitstring@plt>
cmp    $0x0,%eax
jne    11e9 <run_remote+0x89>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <help_rlogin@plt>
mov    %eax,-0x4(%rbp)
jmp    1290 <run_remote+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
xor    %edi,%edi
lea    0xe0f(%rip),%rsi
call   1070 <open_remote@plt>
mov    %eax,-0x4(%rbp)
jmp    1290 <run_remote+0x130>
cmpl   $0x3,-0x8(%rbp)
jne    127c <run_remote+0x11c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <digitstring@plt>
cmp    $0x0,%eax
jne    124e <run_remote+0xee>
lea    0xdcd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <help_rlogin@plt>
mov    %eax,-0x4(%rbp)
jmp    1290 <run_remote+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
xor    %edi,%edi
call   1070 <open_remote@plt>
mov    %eax,-0x4(%rbp)
jmp    1290 <run_remote+0x130>
jmp    1281 <run_remote+0x121>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <help_rlogin@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_remote>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movslq %edi,%rax
mov    -0x8(%rsi,%rax,8),%rdi
lea    0xe89(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11ab <run_remote+0x4b>
cmp    $0x3,%ebp
je     11bb <run_remote+0x5b>
cmp    $0x2,%ebp
jne    11ab <run_remote+0x4b>
mov    0x8(%rbx),%rdi
call   1060 <digitstring@plt>
test   %eax,%eax
je     11e7 <run_remote+0x87>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
lea    0xe5b(%rip),%rsi
xor    %edi,%edi
jmp    11da <run_remote+0x7a>
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <help_rlogin@plt>
mov    0x10(%rbx),%rdi
call   1060 <digitstring@plt>
test   %eax,%eax
je     11fa <run_remote+0x9a>
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <open_remote@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
jmp    11ad <run_remote+0x4d>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
jmp    11ad <run_remote+0x4d>

LLVM IR (-O0):
@.str = [2 x i8] c"?\00"
@.str.1 = [14 x i8] c"Invalid port\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
define i32 @run_remote(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i8**, i8*** %5
%7 = load i32, i32* %4
%8 = sub nsw i32 %7, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8*, i8** %6, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @help_rlogin(i32 %15, i8** %16)
store i32 %17, i32* %3
br label %66
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @digitstring(i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call i32 @help_rlogin(i32 %29, i8** %30)
store i32 %31, i32* %3
br label %66
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @open_remote(i32 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 %37, i32* %3
br label %66
38: ; preds = %18
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 3
br i1 %40, label %41, label %61
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 @digitstring(i8* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %41
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32, i32* %4
%50 = load i8**, i8*** %5
%51 = call i32 @help_rlogin(i32 %49, i8** %50)
store i32 %51, i32* %3
br label %66
52: ; preds = %41
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @atoi(i8* %58)
%60 = call i32 @open_remote(i32 0, i8* %55, i32 %59)
store i32 %60, i32* %3
br label %66
61: ; preds = %38
br label %62
62: ; preds = %61
%63 = load i32, i32* %4
%64 = load i8**, i8*** %5
%65 = call i32 @help_rlogin(i32 %63, i8** %64)
store i32 %65, i32* %3
br label %66
66: ; preds = %62, %52, %47, %32, %27, %14
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"?\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@str.3 = [13 x i8] c"Invalid port\00"
define i32 @run_remote(i32 %0, i8** %1) {
%3 = add nsw i32 %0, -1
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8*, i8** %1, i64 %4
%6 = load i8*, i8** %5
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %6, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @help_rlogin(i32 %0, i8** %1)
br label %40
11: ; preds = %2
switch i32 %0, label %38 [
i32 2, label %12
i32 3, label %24
]
12: ; preds = %11
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @digitstring(i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0))
%19 = tail call i32 @help_rlogin(i32 2, i8** %1)
br label %40
20: ; preds = %12
%21 = load i8*, i8** %13
%22 = tail call i32 @atoi(i8* %21)
%23 = tail call i32 @open_remote(i32 0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %40
24: ; preds = %11
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 @digitstring(i8* %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.3, i64 0, i64 0))
%31 = tail call i32 @help_rlogin(i32 3, i8** %1)
br label %40
32: ; preds = %24
%33 = getelementptr inbounds i8*, i8** %1, i64 1
%34 = load i8*, i8** %33
%35 = load i8*, i8** %25
%36 = tail call i32 @atoi(i8* %35)
%37 = tail call i32 @open_remote(i32 0, i8* %34, i32 %36)
br label %40
38: ; preds = %11
%39 = tail call i32 @help_rlogin(i32 %0, i8** %1)
br label %40
40: ; preds = %38, %32, %29, %20, %17, %9
%41 = phi i32 [ %23, %20 ], [ %19, %17 ], [ %37, %32 ], [ %31, %29 ], [ %39, %38 ], [ %10, %9 ]
ret i32 %41
}