#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
char *exec_cmd(char const *, char const *, char *, int);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
void rce_http_shell(const char *url, const char *parameter, int technique) {
  char *ptr = NULL;
  size_t size = 0;
  ssize_t n;
  setvbuf(stdout, NULL, _IONBF, 0);
  while (1) {
    printf("(kadimus~shell)> ");
    if ((n = getline(&ptr, &size, stdin)) == -1) {
      break;
    }
    if (n == 1 && ptr[0] == '\n') {
      continue;
    }
    if (ptr[n - 1] == '\n') {
      ptr[--n] = 0x0;
    }
    if (!strcmp(ptr, "exit")) {
      break;
    }
    char *rce = exec_cmd(url, parameter, ptr, technique);
    if (rce) {
      printf("%s", rce);
      free(rce);
    }
  }
  free(ptr);
}


x86 assembly (clang, -O0):
<rce_http_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11d5 <rce_http_shell+0x75>
jmp    1283 <rce_http_shell+0x123>
cmpl   $0x1,-0x2c(%rbp)
jne    11f4 <rce_http_shell+0x94>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11f4 <rce_http_shell+0x94>
jmp    11a0 <rce_http_shell+0x40>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1222 <rce_http_shell+0xc2>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1240 <rce_http_shell+0xe0>
jmp    1283 <rce_http_shell+0x123>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <exec_cmd@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     127e <rce_http_shell+0x11e>
mov    -0x38(%rbp),%rsi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    11a0 <rce_http_shell+0x40>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rce_http_shell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   1070 <setvbuf@plt>
lea    0x10(%rsp),%r13
nopl   0x0(%rax)
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1080 <getline@plt>
cmp    $0x1,%eax
je     11f0 <rce_http_shell+0x90>
cmp    $0xffffffff,%eax
je     125e <rce_http_shell+0xfe>
mov    0x8(%rsp),%r15
jmp    11fb <rce_http_shell+0x9b>
nopl   0x0(%rax)
mov    0x8(%rsp),%r15
cmpb   $0xa,(%r15)
je     11b0 <rce_http_shell+0x50>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    1210 <rce_http_shell+0xb0>
movb   $0x0,-0x1(%r15,%rax,1)
mov    0x8(%rsp),%r15
mov    %r15,%rdi
lea    0xdf8(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1263 <rce_http_shell+0x103>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1060 <exec_cmd@plt>
test   %rax,%rax
je     11b0 <rce_http_shell+0x50>
mov    %rax,%rbx
lea    0xdd0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11b0 <rce_http_shell+0x50>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [18 x i8] c"(kadimus~shell)> \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [3 x i8] c"%s\00"
define void @rce_http_shell(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
store i64 0, i64* %8
%11 = load i32, i32* @stdout
%12 = load i32, i32* @_IONBF
%13 = call i32 @setvbuf(i32 %11, i32* null, i32 %12, i32 0)
br label %14
14: ; preds = %3, %29, %63
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stdin
%17 = call i32 @getline(i8** %7, i64* %8, i32 %16)
store i32 %17, i32* %9
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %14
br label %64
20: ; preds = %14
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %30
29: ; preds = %23
br label %14
30: ; preds = %23, %20
%31 = load i8*, i8** %7
%32 = load i32, i32* %9
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %45
39: ; preds = %30
%40 = load i8*, i8** %7
%41 = load i32, i32* %9
%42 = add nsw i32 %41, -1
store i32 %42, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %39, %30
%46 = load i8*, i8** %7
%47 = call i32 @strcmp(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
br label %64
50: ; preds = %45
%51 = load i8*, i8** %4
%52 = load i8*, i8** %5
%53 = load i8*, i8** %7
%54 = load i32, i32* %6
%55 = call i8* @exec_cmd(i8* %51, i8* %52, i8* %53, i32 %54)
store i8* %55, i8** %10
%56 = load i8*, i8** %10
%57 = icmp ne i8* %56, null
br i1 %57, label %58, label %63
58: ; preds = %50
%59 = load i8*, i8** %10
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = load i8*, i8** %10
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %58, %50
br label %14
64: ; preds = %49, %19
%65 = load i8*, i8** %7
%66 = call i32 @free(i8* %65)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@_IONBF = global i32 0
@.str = [18 x i8] c"(kadimus~shell)> \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [3 x i8] c"%s\00"
define void @rce_http_shell(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = load i32, i32* @stdout
%9 = load i32, i32* @_IONBF
%10 = tail call i32 @setvbuf(i32 %8, i32* null, i32 %9, i32 0)
br label %11
11: ; preds = %39, %3
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @getline(i8** %4, i64* %5, i32 %13)
switch i32 %14, label %17 [
i32 -1, label %15
i32 1, label %19
]
15: ; preds = %11
%16 = load i8*, i8** %4
br label %43
17: ; preds = %11
%18 = load i8*, i8** %4
br label %23
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %39, label %23
23: ; preds = %17, %19
%24 = phi i8* [ %18, %17 ], [ %20, %19 ]
%25 = add nsw i32 %14, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %32
30: ; preds = %23
store i8 0, i8* %27
%31 = load i8*, i8** %4
br label %32
32: ; preds = %30, %23
%33 = phi i8* [ %31, %30 ], [ %24, %23 ]
%34 = call i32 @strcmp(i8* dereferenceable(1) %33, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i32 %34, 0
br i1 %35, label %43, label %36
36: ; preds = %32
%37 = call i8* @exec_cmd(i8* %0, i8* %1, i8* %33, i32 %2)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %40
39: ; preds = %36, %40, %19
br label %11
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%42 = call i32 @free(i8* %37)
br label %39
43: ; preds = %32, %15
%44 = phi i8* [ %16, %15 ], [ %33, %32 ]
%45 = call i32 @free(i8* %44)
ret void
}