#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*/ get_tty();
int /*<<< orphan*/ init_tty();
int /*<<< orphan*/ proc(char *, int);
int /*<<< orphan*/ reset_tty();
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argn, char *argc[]) {
  char remotehost[256] = "localhost";
  int remoteport = 23;
  get_tty();
  init_tty();
  if (argn >= 2)
    strncpy(remotehost, argc[1], 255);
  remotehost[255] = 0;
  if (argn >= 3)
    remoteport = atoi(argc[2]);
  proc(remotehost, remoteport);
  reset_tty();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x100,%edx
call   1060 <memcpy@plt>
movl   $0x17,-0x114(%rbp)
mov    $0x0,%al
call   1040 <get_tty@plt>
mov    $0x0,%al
call   1090 <init_tty@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11dc <main+0x6c>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11fd <main+0x8d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x114(%rbp),%esi
call   1050 <proc@plt>
mov    $0x0,%al
call   1070 <reset_tty@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe7b(%rip),%rsi
mov    %rsp,%rdi
mov    $0x100,%edx
call   1060 <memcpy@plt>
xor    %eax,%eax
call   1040 <get_tty@plt>
xor    %eax,%eax
call   1090 <init_tty@plt>
cmp    $0x1,%ebp
jle    11d5 <main+0x65>
mov    0x8(%rbx),%rsi
mov    %rsp,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xff(%rsp)
mov    $0x17,%esi
cmp    $0x2,%ebp
je     11e2 <main+0x72>
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
jmp    11e2 <main+0x72>
movb   $0x0,0xff(%rsp)
mov    $0x17,%esi
mov    %rsp,%rdi
call   1050 <proc@plt>
xor    %eax,%eax
call   1070 <reset_tty@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.remotehost = [256 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [256 x i8]* %6 to i8*
store i32 23, i32* %7
%9 = call i32 (...) @get_tty()
%10 = call i32 (...) @init_tty()
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strncpy(i8* %14, i8* %17, i32 255)
br label %19
19: ; preds = %13, %2
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 255
store i8 0, i8* %20
%21 = load i32, i32* %4
%22 = icmp sge i32 %21, 3
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
br label %28
28: ; preds = %23, %19
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @proc(i8* %29, i32 %30)
%32 = call i32 (...) @reset_tty()
ret i32 0
}

LLVM IR (-O2):
@__const.main.remotehost = [256 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @get_tty()
%6 = tail call i32 (...) @init_tty()
%7 = icmp sgt i32 %0, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %9
br label %20
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strncpy(i8* %4, i8* %12, i32 255)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %14
%15 = icmp eq i32 %0, 2
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
br label %20
20: ; preds = %8, %16, %10
%21 = phi i32 [ %19, %16 ], [ 23, %10 ], [ 23, %8 ]
%22 = call i32 @proc(i8* %4, i32 %21)
%23 = call i32 (...) @reset_tty()
ret i32 0
}