#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 /*<<< orphan*/ username;
typedef int /*<<< orphan*/ response;
typedef int /*<<< orphan*/ password;

/* Variables and functions */
int cconnect(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recvall(int, int *, int);
int /*<<< orphan*/ sendall(int, char *, int);
int /*<<< orphan*/ sendpacked(int, int, int, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char const *, int);
int boitho_authenticat(const char username_in[], char password_in[]) {
  int socketha;
  int response;
  char username[64];
  char password[64];
  strncpy(username, username_in, sizeof(username));
  strncpy(password, password_in, sizeof(password));
  if ((socketha = cconnect("localhost", 3491)) == 0) {
    perror("localhost");
    return 0;
  }
  sendpacked(socketha, 1, 1, 0, NULL, "");
  sendall(socketha, username, sizeof(username));
  sendall(socketha, password, sizeof(password));
  recvall(socketha, &response, sizeof(response));
  close(socketha);
  if (response == 111) {
    return 1;
  } else if (response == 000) {
    return 0;
  } else if (response == 112) {
    return 2;
  } else {
    fprintf(
        stderr,
        "dident get ad_userauthenticated_ERROR or ad_userauthenticated_OK\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<boitho_authenticat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    0xe3f(%rip),%rdi
mov    $0xda3,%esi
call   10a0 <cconnect@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11ef <boitho_authenticat+0x6f>
lea    0xe22(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <boitho_authenticat+0x128>
mov    -0x1c(%rbp),%edi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe46(%rip),%r9
mov    %edx,%esi
call   1090 <sendpacked@plt>
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1070 <sendall@plt>
mov    -0x1c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x40,%edx
call   1070 <sendall@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1050 <recvall@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x6f,-0x20(%rbp)
jne    1260 <boitho_authenticat+0xe0>
movl   $0x1,-0x4(%rbp)
jmp    12a8 <boitho_authenticat+0x128>
cmpl   $0x0,-0x20(%rbp)
jne    1276 <boitho_authenticat+0xf6>
movl   $0x0,-0x4(%rbp)
jmp    12a8 <boitho_authenticat+0x128>
cmpl   $0x70,-0x20(%rbp)
jne    128c <boitho_authenticat+0x10c>
movl   $0x2,-0x4(%rbp)
jmp    12a8 <boitho_authenticat+0x128>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<boitho_authenticat>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0x50(%rsp),%rdi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    0xe49(%rip),%rdi
mov    $0xda3,%esi
call   10a0 <cconnect@plt>
test   %eax,%eax
je     1257 <boitho_authenticat+0xd7>
mov    %eax,%ebp
lea    0xe79(%rip),%r9
mov    $0x1,%ebx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <sendpacked@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x40,%edx
call   1070 <sendall@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x40,%edx
call   1070 <sendall@plt>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1050 <recvall@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0xc(%rsp),%eax
cmp    $0x70,%eax
je     1250 <boitho_authenticat+0xd0>
cmp    $0x6f,%eax
je     1265 <boitho_authenticat+0xe5>
test   %eax,%eax
je     1263 <boitho_authenticat+0xe3>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1263 <boitho_authenticat+0xe3>
mov    $0x2,%ebx
jmp    1265 <boitho_authenticat+0xe5>
lea    0xda2(%rip),%rdi
call   1080 <perror@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [66 x i8] c"dident get ad_userauthenticated_ERROR or ad_userauthenticated_OK\0A\00"
define i32 @boitho_authenticat(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca [64 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 64)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = call i32 @strncpy(i8* %13, i8* %14, i32 64)
%16 = call i32 @cconnect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 3491)
store i32 %16, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %47
20: ; preds = %2
%21 = load i32, i32* %6
%22 = call i32 @sendpacked(i32 %21, i32 1, i32 1, i32 0, i32* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %6
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%25 = call i32 @sendall(i32 %23, i8* %24, i32 64)
%26 = load i32, i32* %6
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%28 = call i32 @sendall(i32 %26, i8* %27, i32 64)
%29 = load i32, i32* %6
%30 = call i32 @recvall(i32 %29, i32* %7, i32 4)
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 111
br i1 %34, label %35, label %36
35: ; preds = %20
store i32 1, i32* %3
br label %47
36: ; preds = %20
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 0, i32* %3
br label %47
40: ; preds = %36
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 112
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 2, i32* %3
br label %47
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %47
47: ; preds = %44, %43, %39, %35, %18
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.2 = [66 x i8] c"dident get ad_userauthenticated_ERROR or ad_userauthenticated_OK\0A\00"
define i32 @boitho_authenticat(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [64 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = call i32 @strncpy(i8* %7, i8* %0, i32 64)
%10 = call i32 @strncpy(i8* %8, i8* %1, i32 64)
%11 = call i32 @cconnect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 3491)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %27
15: ; preds = %2
%16 = call i32 @sendpacked(i32 %11, i32 1, i32 1, i32 0, i32* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @sendall(i32 %11, i8* %7, i32 64)
%18 = call i32 @sendall(i32 %11, i8* %8, i32 64)
%19 = call i32 @recvall(i32 %11, i32* %3, i32 4)
%20 = call i32 @close(i32 %11)
%21 = load i32, i32* %3
switch i32 %21, label %24 [
i32 111, label %27
i32 0, label %22
i32 112, label %23
]
22: ; preds = %15
br label %27
23: ; preds = %15
br label %27
24: ; preds = %15
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %15, %24, %23, %22, %13
%28 = phi i32 [ 0, %13 ], [ 0, %22 ], [ 2, %23 ], [ 0, %24 ], [ 1, %15 ]
ret i32 %28
}