#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 */
scalar_t__ challangeHashReceived(char *);
int /*<<< orphan*/ debugPrint(char *);
char *receive(int);
scalar_t__ sendClientInfo(int, char *);
scalar_t__ sendMSNVersion(int);
int sendUserInfo(int, char *);
scalar_t__ serverRedirectRequested(char *);
int initiate(int streamID, char *username) {
  if (sendMSNVersion(streamID)) {
    debugPrint("ERROR : msn : initiate : couldnt send msn version");
    return -1;
  } else {
    if (serverRedirectRequested(receive(streamID)) == 0) {
      debugPrint("INFO : msn : initiate server redirect 1");
      return -2;
    }
    if (sendClientInfo(streamID, username)) {
      debugPrint("ERROR : msn : initiate : couldnt send client info");
      return -1;
    } else {
      if (serverRedirectRequested(receive(streamID)) == 0) {
        return -2;
      }
      if (sendUserInfo(streamID, username) == -1) {
        return -1;
      } else {
        char *recvd = receive(streamID);
        if (serverRedirectRequested(recvd) == 0) {
          return -2;
        } else if (challangeHashReceived(recvd) == 0) {
          debugPrint("INFO : msn : initiate : success");
          return 0;
        } else {
          return -1;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<initiate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <sendMSNVersion@plt>
cmp    $0x0,%rax
je     11a9 <initiate+0x39>
lea    0xe68(%rip),%rdi
call   1070 <debugPrint@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x8(%rbp),%edi
call   1060 <receive@plt>
mov    %rax,%rdi
call   1080 <serverRedirectRequested@plt>
cmp    $0x0,%rax
jne    11db <initiate+0x6b>
lea    0xe68(%rip),%rdi
call   1070 <debugPrint@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <sendClientInfo@plt>
cmp    $0x0,%rax
je     1209 <initiate+0x99>
lea    0xe62(%rip),%rdi
call   1070 <debugPrint@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x8(%rbp),%edi
call   1060 <receive@plt>
mov    %rax,%rdi
call   1080 <serverRedirectRequested@plt>
cmp    $0x0,%rax
jne    122f <initiate+0xbf>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <sendUserInfo@plt>
cmp    $0xffffffff,%eax
jne    1250 <initiate+0xe0>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x8(%rbp),%edi
call   1060 <receive@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <serverRedirectRequested@plt>
cmp    $0x0,%rax
jne    127b <initiate+0x10b>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
mov    -0x18(%rbp),%rdi
call   1050 <challangeHashReceived@plt>
cmp    $0x0,%rax
jne    12a6 <initiate+0x136>
lea    0xdf7(%rip),%rdi
call   1070 <debugPrint@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ad <initiate+0x13d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initiate>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
call   1030 <sendMSNVersion@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     119b <initiate+0x2b>
lea    0xe71(%rip),%rdi
call   1070 <debugPrint@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
call   1060 <receive@plt>
mov    %rax,%rdi
call   1080 <serverRedirectRequested@plt>
test   %rax,%rax
je     11c7 <initiate+0x57>
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <sendClientInfo@plt>
test   %rax,%rax
je     11d5 <initiate+0x65>
lea    0xe95(%rip),%rdi
jmp    118f <initiate+0x1f>
mov    $0xfffffffe,%ebx
lea    0xe5f(%rip),%rdi
jmp    118f <initiate+0x1f>
mov    %ebp,%edi
call   1060 <receive@plt>
mov    %rax,%rdi
call   1080 <serverRedirectRequested@plt>
mov    $0xfffffffe,%ebx
test   %rax,%rax
je     1194 <initiate+0x24>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <sendUserInfo@plt>
cmp    $0xffffffff,%eax
je     1238 <initiate+0xc8>
mov    %ebp,%edi
call   1060 <receive@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <serverRedirectRequested@plt>
test   %rax,%rax
je     1194 <initiate+0x24>
mov    %rbp,%rdi
call   1050 <challangeHashReceived@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1194 <initiate+0x24>
xor    %ebx,%ebx
lea    0xe59(%rip),%rdi
jmp    118f <initiate+0x1f>
mov    $0xffffffff,%ebx
jmp    1194 <initiate+0x24>

LLVM IR (-O0):
@.str = [50 x i8] c"ERROR : msn : initiate : couldnt send msn version\00"
@.str.1 = [40 x i8] c"INFO : msn : initiate server redirect 1\00"
@.str.2 = [50 x i8] c"ERROR : msn : initiate : couldnt send client info\00"
@.str.3 = [32 x i8] c"INFO : msn : initiate : success\00"
define i32 @initiate(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i32, i32* %4
%8 = call i64 @sendMSNVersion(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @debugPrint(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %52
12: ; preds = %2
%13 = load i32, i32* %4
%14 = call i8* @receive(i32 %13)
%15 = call i64 @serverRedirectRequested(i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @debugPrint(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %52
19: ; preds = %12
%20 = load i32, i32* %4
%21 = load i8*, i8** %5
%22 = call i64 @sendClientInfo(i32 %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @debugPrint(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %52
26: ; preds = %19
%27 = load i32, i32* %4
%28 = call i8* @receive(i32 %27)
%29 = call i64 @serverRedirectRequested(i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 -2, i32* %3
br label %52
32: ; preds = %26
%33 = load i32, i32* %4
%34 = load i8*, i8** %5
%35 = call i32 @sendUserInfo(i32 %33, i8* %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 -1, i32* %3
br label %52
38: ; preds = %32
%39 = load i32, i32* %4
%40 = call i8* @receive(i32 %39)
store i8* %40, i8** %6
%41 = load i8*, i8** %6
%42 = call i64 @serverRedirectRequested(i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 -2, i32* %3
br label %52
45: ; preds = %38
%46 = load i8*, i8** %6
%47 = call i64 @challangeHashReceived(i8* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @debugPrint(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %52
51: ; preds = %45
store i32 -1, i32* %3
br label %52
52: ; preds = %51, %49, %44, %37, %31, %24, %17, %10
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [50 x i8] c"ERROR : msn : initiate : couldnt send msn version\00"
@.str.1 = [40 x i8] c"INFO : msn : initiate server redirect 1\00"
@.str.2 = [50 x i8] c"ERROR : msn : initiate : couldnt send client info\00"
@.str.3 = [32 x i8] c"INFO : msn : initiate : success\00"
define i32 @initiate(i32 %0, i8* %1) {
%3 = tail call i64 @sendMSNVersion(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = tail call i8* @receive(i32 %0)
%7 = tail call i64 @serverRedirectRequested(i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %5
%10 = tail call i64 @sendClientInfo(i32 %0, i8* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = tail call i8* @receive(i32 %0)
%14 = tail call i64 @serverRedirectRequested(i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %12
%17 = tail call i32 @sendUserInfo(i32 %0, i8* %1)
%18 = icmp eq i32 %17, -1
br i1 %18, label %30, label %19
19: ; preds = %16
%20 = tail call i8* @receive(i32 %0)
%21 = tail call i64 @serverRedirectRequested(i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = tail call i64 @challangeHashReceived(i8* %20)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23, %9, %5, %2
%27 = phi i8* [ getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), %23 ]
%28 = phi i32 [ -1, %2 ], [ -2, %5 ], [ -1, %9 ], [ 0, %23 ]
%29 = tail call i32 @debugPrint(i8* %27)
br label %30
30: ; preds = %26, %19, %23, %16, %12
%31 = phi i32 [ -2, %12 ], [ -1, %16 ], [ -2, %19 ], [ -1, %23 ], [ %28, %26 ]
ret i32 %31
}