#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*/ cmd_exit();
int /*<<< orphan*/ estb_conn(char *, unsigned short);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
void cmd_fun(int cmd_num) {
  if (cmd_num == 0) {
    char *remote_addr = malloc(sizeof(char) * 16);
    unsigned short int remote_port;
    printf("[cmd][enter ip] ");
    scanf("%s", &remote_addr);
    printf("\n[cmd][enter port] ");
    scanf("%u", &remote_port);
    printf("\n[info] Trying to connect to %s on port %u\n", remote_addr,
           remote_port);
    estb_conn(remote_addr, remote_port);
  }
  if (cmd_num == 1)
    cmd_exit();
}


x86 assembly (clang, -O0):
<cmd_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11d6 <cmd_fun+0x86>
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe89(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0x12(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rsi
movzwl -0x12(%rbp),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
movzwl -0x12(%rbp),%esi
call   1070 <estb_conn@plt>
cmpl   $0x1,-0x4(%rbp)
jne    11e7 <cmd_fun+0x97>
mov    $0x0,%al
call   1040 <cmd_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_fun>:
cmp    $0x1,%edi
je     11e2 <cmd_fun+0x92>
test   %edi,%edi
jne    11e1 <cmd_fun+0x91>
sub    $0x18,%rsp
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rsp)
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7e(%rip),%rdi
lea    0xe(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%rsi
movzwl 0xe(%rsp),%edx
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%rdi
movzwl 0xe(%rsp),%esi
call   1070 <estb_conn@plt>
add    $0x18,%rsp
ret
xor    %eax,%eax
jmp    1040 <cmd_exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"[cmd][enter ip] \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"\0A[cmd][enter port] \00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [44 x i8] c"\0A[info] Trying to connect to %s on port %u\0A\00"
define void @cmd_fun(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i16
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = call i8* @malloc(i32 16)
store i8* %8, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i16* %4)
%13 = load i8*, i8** %3
%14 = load i16, i16* %4
%15 = zext i16 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %13, i32 %15)
%17 = load i8*, i8** %3
%18 = load i16, i16* %4
%19 = call i32 @estb_conn(i8* %17, i16 zeroext %18)
br label %20
20: ; preds = %7, %1
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (...) @cmd_exit()
br label %25
25: ; preds = %23, %20
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"[cmd][enter ip] \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"\0A[cmd][enter port] \00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [44 x i8] c"\0A[info] Trying to connect to %s on port %u\0A\00"
define void @cmd_fun(i32 %0) {
%2 = alloca i8*
%3 = alloca i16
switch i32 %0, label %21 [
i32 0, label %4
i32 1, label %19
]
4: ; preds = %1
%5 = bitcast i8** %2 to i8*
%6 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
store i8* %6, i8** %2
%7 = bitcast i16* %3 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %2)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i16* %3)
%12 = load i8*, i8** %2
%13 = load i16, i16* %3
%14 = zext i16 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %12, i32 %14)
%16 = load i8*, i8** %2
%17 = load i16, i16* %3
%18 = call i32 @estb_conn(i8* %16, i16 zeroext %17)
br label %21
19: ; preds = %1
%20 = tail call i32 (...) @cmd_exit()
br label %21
21: ; preds = %4, %1, %19
ret void
}