#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 */
void *SMB_Connect_Server(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ SMB_Discon(void *, int /*<<< orphan*/);
int /*<<< orphan*/ SMB_Init();
scalar_t__ SMB_Logon_Server(void *, char *, char *);
scalar_t__ SMB_Negotiate(void *, char const **);
int Valid_User(char *USERNAME, char *PASSWORD, char *SERVER, char *BACKUP,
               char *DOMAIN) {
  const char *SMB_Prots[] = {"PC NETWORK PROGRAM 1.0",
                             "MICROSOFT NETWORKS 1.03",
                             "MICROSOFT NETWORKS 3.0",
                             "LANMAN1.0",
                             "LM1.2X002",
                             "Samba",
                             "NT LM 0.12",
                             "NT LANMAN 1.0",
                             NULL};
  void *con;
  SMB_Init();
  con = SMB_Connect_Server(NULL, SERVER, DOMAIN);
  if (con == NULL) {
    con = SMB_Connect_Server(NULL, BACKUP, DOMAIN);
    if (con == NULL) {
      return (1);
    }
  }
  if (SMB_Negotiate(con, SMB_Prots) < 0) {
    SMB_Discon(con, 0);
    return (2);
  }
  if (SMB_Logon_Server(con, USERNAME, PASSWORD) < 0) {
    SMB_Discon(con, 0);
    return (3);
  }
  SMB_Discon(con, 0);
  return (0);
}


x86 assembly (clang, -O0):
<Valid_User>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2c46(%rip),%rsi
mov    $0x48,%edx
call   1050 <memcpy@plt>
mov    $0x0,%al
call   1030 <SMB_Init@plt>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1070 <SMB_Connect_Server@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11f8 <Valid_User+0x98>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1070 <SMB_Connect_Server@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11f3 <Valid_User+0x93>
movl   $0x1,-0x4(%rbp)
jmp    1279 <Valid_User+0x119>
jmp    11f8 <Valid_User+0x98>
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1080 <SMB_Negotiate@plt>
cmp    $0x0,%rax
jge    122c <Valid_User+0xcc>
mov    -0x88(%rbp),%rdi
xor    %esi,%esi
call   1060 <SMB_Discon@plt>
movl   $0x2,-0x4(%rbp)
jmp    1279 <Valid_User+0x119>
mov    -0x88(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <SMB_Logon_Server@plt>
cmp    $0x0,%rax
jge    1264 <Valid_User+0x104>
mov    -0x88(%rbp),%rdi
xor    %esi,%esi
call   1060 <SMB_Discon@plt>
movl   $0x3,-0x4(%rbp)
jmp    1279 <Valid_User+0x119>
mov    -0x88(%rbp),%rdi
xor    %esi,%esi
call   1060 <SMB_Discon@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Valid_User>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2c9c(%rip),%rax
mov    %rax,0x40(%rsp)
movaps 0x2c80(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c64(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c48(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c2c(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <SMB_Init@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1060 <SMB_Connect_Server@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11d9 <Valid_User+0x89>
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <SMB_Connect_Server@plt>
mov    %rax,%rbp
test   %rax,%rax
je     121e <Valid_User+0xce>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1070 <SMB_Negotiate@plt>
test   %rax,%rax
js     120d <Valid_User+0xbd>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <SMB_Logon_Server@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <SMB_Discon@plt>
sar    $0x3f,%rbx
and    $0x3,%ebx
jmp    1223 <Valid_User+0xd3>
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <SMB_Discon@plt>
mov    $0x2,%ebx
jmp    1223 <Valid_User+0xd3>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"PC NETWORK PROGRAM 1.0\00"
@.str.1 = [24 x i8] c"MICROSOFT NETWORKS 1.03\00"
@.str.2 = [23 x i8] c"MICROSOFT NETWORKS 3.0\00"
@.str.3 = [10 x i8] c"LANMAN1.0\00"
@.str.4 = [10 x i8] c"LM1.2X002\00"
@.str.5 = [6 x i8] c"Samba\00"
@.str.6 = [11 x i8] c"NT LM 0.12\00"
@.str.7 = [14 x i8] c"NT LANMAN 1.0\00"
@__const.Valid_User.SMB_Prots = [9 x i8*] [i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i32 0, i32 0), i8* null]
define i32 @Valid_User(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca [9 x i8*]
%13 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%14 = bitcast [9 x i8*]* %12 to i8*
%15 = call i32 (...) @SMB_Init()
%16 = load i8*, i8** %9
%17 = load i8*, i8** %11
%18 = call i8* @SMB_Connect_Server(i32* null, i8* %16, i8* %17)
store i8* %18, i8** %13
%19 = load i8*, i8** %13
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %5
%22 = load i8*, i8** %10
%23 = load i8*, i8** %11
%24 = call i8* @SMB_Connect_Server(i32* null, i8* %22, i8* %23)
store i8* %24, i8** %13
%25 = load i8*, i8** %13
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 1, i32* %6
br label %49
28: ; preds = %21
br label %29
29: ; preds = %28, %5
%30 = load i8*, i8** %13
%31 = getelementptr inbounds [9 x i8*], [9 x i8*]* %12, i64 0, i64 0
%32 = call i64 @SMB_Negotiate(i8* %30, i8** %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %13
%36 = call i32 @SMB_Discon(i8* %35, i32 0)
store i32 2, i32* %6
br label %49
37: ; preds = %29
%38 = load i8*, i8** %13
%39 = load i8*, i8** %7
%40 = load i8*, i8** %8
%41 = call i64 @SMB_Logon_Server(i8* %38, i8* %39, i8* %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i8*, i8** %13
%45 = call i32 @SMB_Discon(i8* %44, i32 0)
store i32 3, i32* %6
br label %49
46: ; preds = %37
%47 = load i8*, i8** %13
%48 = call i32 @SMB_Discon(i8* %47, i32 0)
store i32 0, i32* %6
br label %49
49: ; preds = %46, %43, %34, %27
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
@.str = [23 x i8] c"PC NETWORK PROGRAM 1.0\00"
@.str.1 = [24 x i8] c"MICROSOFT NETWORKS 1.03\00"
@.str.2 = [23 x i8] c"MICROSOFT NETWORKS 3.0\00"
@.str.3 = [10 x i8] c"LANMAN1.0\00"
@.str.4 = [10 x i8] c"LM1.2X002\00"
@.str.5 = [6 x i8] c"Samba\00"
@.str.6 = [11 x i8] c"NT LM 0.12\00"
@.str.7 = [14 x i8] c"NT LANMAN 1.0\00"
@__const.Valid_User.SMB_Prots = [9 x i8*] [i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i32 0, i32 0), i8* null]
define i32 @Valid_User(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [9 x i8*]
%7 = bitcast [9 x i8*]* %6 to i8*
%8 = tail call i32 (...) @SMB_Init()
%9 = tail call i8* @SMB_Connect_Server(i32* null, i8* %2, i8* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i8* @SMB_Connect_Server(i32* null, i8* %3, i8* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %11, %5
%15 = phi i8* [ %12, %11 ], [ %9, %5 ]
%16 = getelementptr inbounds [9 x i8*], [9 x i8*]* %6, i64 0, i64 0
%17 = call i64 @SMB_Negotiate(i8* %15, i8** %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @SMB_Discon(i8* %15, i32 0)
br label %26
21: ; preds = %14
%22 = call i64 @SMB_Logon_Server(i8* %15, i8* %0, i8* %1)
%23 = icmp slt i64 %22, 0
%24 = call i32 @SMB_Discon(i8* %15, i32 0)
%25 = select i1 %23, i32 3, i32 0
br label %26
26: ; preds = %21, %11, %19
%27 = phi i32 [ 2, %19 ], [ 1, %11 ], [ %25, %21 ]
ret i32 %27
}