#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*/ exit(int);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int pre_cmd(int sd, int precmd, int verbose) {
  int rc, go = 0;
  char *buffer;
  char *line1;
  char *line2;
  switch (precmd) {
  case 0:
    line1 = "EHLO test\n";
    line2 = "STARTTLS\n";
    break;
  case 1:
    line1 = "CAPA\n";
    line2 = "STLS\n";
    break;
  case 2:
    line1 = "a001 CAPB\n";
    line2 = "a002 STARTTLS\n";
    break;
  default:
    go = 1;
    break;
  }
  if (go == 0) {
    buffer = malloc(2049);
    if (buffer == NULL) {
      exit(8);
    }
    memset(buffer, 0, 2049);
    rc = read(sd, buffer, 2048);
    printf("[ banner: %s", buffer);
    send(sd, line1, strlen(line1), 0);
    memset(buffer, 0, 2049);
    rc = read(sd, buffer, 2048);
    if (verbose == 1) {
      printf("%s\n", buffer);
    }
    send(sd, line2, strlen(line2), 0);
    memset(buffer, 0, 2049);
    rc = read(sd, buffer, 2048);
    if (verbose == 1) {
      printf("%s\n", buffer);
    }
  }
  return sd;
}


x86 assembly (clang, -O0):
<pre_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     11bd <pre_cmd+0x4d>
jmp    119b <pre_cmd+0x2b>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     11d8 <pre_cmd+0x68>
jmp    11ac <pre_cmd+0x3c>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     11f3 <pre_cmd+0x83>
jmp    120e <pre_cmd+0x9e>
lea    0xe3c(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe58(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1215 <pre_cmd+0xa5>
lea    0xe2c(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe27(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1215 <pre_cmd+0xa5>
lea    0xe1d(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe1d(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1215 <pre_cmd+0xa5>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1345 <pre_cmd+0x1d5>
mov    $0x801,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1242 <pre_cmd+0xd2>
mov    $0x8,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    12db <pre_cmd+0x16b>
mov    -0x20(%rbp),%rsi
lea    0xd68(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1340 <pre_cmd+0x1d0>
mov    -0x20(%rbp),%rsi
lea    0xd03(%rip),%rdi
call   1050 <printf@plt>
jmp    1345 <pre_cmd+0x1d5>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pre_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
cmp    $0x2,%esi
ja     12b0 <pre_cmd+0x140>
mov    %edx,%r15d
mov    %esi,%ebp
mov    $0x801,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12c2 <pre_cmd+0x152>
mov    %rax,%rbx
movslq %ebp,%rax
lea    0x2c44(%rip),%rcx
mov    (%rcx,%rax,8),%r12
lea    0x2c51(%rip),%rcx
mov    (%rcx,%rax,8),%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
cmp    $0x1,%r15d
jne    127a <pre_cmd+0x10a>
lea    0xe12(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    12b0 <pre_cmd+0x140>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x801,%edx
call   1060 <memset@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1070 <read@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x8,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"EHLO test\0A\00"
@.str.1 = [10 x i8] c"STARTTLS\0A\00"
@.str.2 = [6 x i8] c"CAPA\0A\00"
@.str.3 = [6 x i8] c"STLS\0A\00"
@.str.4 = [11 x i8] c"a001 CAPB\0A\00"
@.str.5 = [15 x i8] c"a002 STARTTLS\0A\00"
@.str.6 = [13 x i8] c"[ banner: %s\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @pre_cmd(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%12 = load i32, i32* %5
switch i32 %12, label %16 [
i32 0, label %13
i32 1, label %14
i32 2, label %15
]
13: ; preds = %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %17
14: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %11
br label %17
15: ; preds = %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %11
br label %17
16: ; preds = %3
store i32 1, i32* %8
br label %17
17: ; preds = %16, %15, %14, %13
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %66
20: ; preds = %17
%21 = call i8* @malloc(i32 2049)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @exit(i32 8)
unreachable
26: ; preds = %20
%27 = load i8*, i8** %9
%28 = call i32 @memset(i8* %27, i32 0, i32 2049)
%29 = load i32, i32* %4
%30 = load i8*, i8** %9
%31 = call i32 @read(i32 %29, i8* %30, i32 2048)
store i32 %31, i32* %7
%32 = load i8*, i8** %9
%33 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %4
%35 = load i8*, i8** %10
%36 = load i8*, i8** %10
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @send(i32 %34, i8* %35, i32 %37, i32 0)
%39 = load i8*, i8** %9
%40 = call i32 @memset(i8* %39, i32 0, i32 2049)
%41 = load i32, i32* %4
%42 = load i8*, i8** %9
%43 = call i32 @read(i32 %41, i8* %42, i32 2048)
store i32 %43, i32* %7
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %49
46: ; preds = %26
%47 = load i8*, i8** %9
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %26
%50 = load i32, i32* %4
%51 = load i8*, i8** %11
%52 = load i8*, i8** %11
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @send(i32 %50, i8* %51, i32 %53, i32 0)
%55 = load i8*, i8** %9
%56 = call i32 @memset(i8* %55, i32 0, i32 2049)
%57 = load i32, i32* %4
%58 = load i8*, i8** %9
%59 = call i32 @read(i32 %57, i8* %58, i32 2048)
store i32 %59, i32* %7
%60 = load i32, i32* %6
%61 = icmp eq i32 %60, 1
br i1 %61, label %62, label %65
62: ; preds = %49
%63 = load i8*, i8** %9
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %49
br label %66
66: ; preds = %65, %17
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
@.str = [11 x i8] c"EHLO test\0A\00"
@.str.1 = [10 x i8] c"STARTTLS\0A\00"
@.str.2 = [6 x i8] c"CAPA\0A\00"
@.str.3 = [6 x i8] c"STLS\0A\00"
@.str.4 = [11 x i8] c"a001 CAPB\0A\00"
@.str.5 = [15 x i8] c"a002 STARTTLS\0A\00"
@.str.6 = [13 x i8] c"[ banner: %s\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@switch.table.pre_cmd = [3 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0)]
@switch.table.pre_cmd.8 = [3 x i8*] [i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0)]
define i32 @pre_cmd(i32 returned %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %1, 3
br i1 %4, label %5, label %37
5: ; preds = %3
%6 = sext i32 %1 to i64
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* @switch.table.pre_cmd, i64 0, i64 %6
%8 = load i8*, i8** %7
%9 = sext i32 %1 to i64
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* @switch.table.pre_cmd.8, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = tail call dereferenceable_or_null(2049) i8* @malloc(i32 2049)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = tail call i32 @exit(i32 8)
unreachable
16: ; preds = %5
%17 = tail call i32 @memset(i8* %12, i32 0, i32 2049)
%18 = tail call i32 @read(i32 %0, i8* %12, i32 2048)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%20 = tail call i32 @strlen(i8* %8)
%21 = tail call i32 @send(i32 %0, i8* %8, i32 %20, i32 0)
%22 = tail call i32 @memset(i8* %12, i32 0, i32 2049)
%23 = tail call i32 @read(i32 %0, i8* %12, i32 2048)
%24 = icmp eq i32 %2, 1
br i1 %24, label %25, label %32
25: ; preds = %16
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %12)
%27 = tail call i32 @strlen(i8* %11)
%28 = tail call i32 @send(i32 %0, i8* %11, i32 %27, i32 0)
%29 = tail call i32 @memset(i8* %12, i32 0, i32 2049)
%30 = tail call i32 @read(i32 %0, i8* %12, i32 2048)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %12)
br label %37
32: ; preds = %16
%33 = tail call i32 @strlen(i8* %11)
%34 = tail call i32 @send(i32 %0, i8* %11, i32 %33, i32 0)
%35 = tail call i32 @memset(i8* %12, i32 0, i32 2049)
%36 = tail call i32 @read(i32 %0, i8* %12, i32 2048)
br label %37
37: ; preds = %3, %32, %25
ret i32 %0
}