#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*/ sid;
typedef int /*<<< orphan*/ intresponse;

/* Variables and functions */
int cconnect(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ recvall(int, ...);
int /*<<< orphan*/ sendall(int, char *, int);
int /*<<< orphan*/ sendpacked(int, int, int, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int boithoad_sidToGroup(char sid_in[], char username_in[]) {
  int socketha;
  int intresponse;
  char username[64];
  char sid[512];
  int forreturn = 0;
  strncpy(sid, sid_in, sizeof(sid));
  if ((socketha = cconnect("localhost", 3491)) == 0) {
    return 0;
  }
  sendpacked(socketha, 41, 1, 0, NULL, "");
  sendall(socketha, sid, sizeof(sid));
  if (!recvall(socketha, &intresponse, sizeof(intresponse))) {
    return 0;
  }
  if (intresponse == 1) {
    if (!recvall(socketha, username, sizeof(username))) {
      return 0;
    }
    strcpy(username_in, username);
    forreturn = 1;
  } else {
    strcpy(username_in, "");
    forreturn = 0;
  }
  close(socketha);
  return forreturn;
}


x86 assembly (clang, -O0):
<boithoad_sidToGroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x264(%rbp)
lea    -0x260(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    0xe57(%rip),%rdi
mov    $0xda3,%esi
call   1090 <cconnect@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11cb <boithoad_sidToGroup+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <boithoad_sidToGroup+0x130>
mov    -0x1c(%rbp),%edi
mov    $0x29,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe23(%rip),%r9
call   1080 <sendpacked@plt>
mov    -0x1c(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x200,%edx
call   1070 <sendall@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <recvall@plt>
cmp    $0x0,%eax
jne    1227 <boithoad_sidToGroup+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <boithoad_sidToGroup+0x130>
cmpl   $0x1,-0x20(%rbp)
jne    1275 <boithoad_sidToGroup+0x105>
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
mov    $0x0,%al
call   1060 <recvall@plt>
cmp    $0x0,%eax
jne    1259 <boithoad_sidToGroup+0xe9>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <boithoad_sidToGroup+0x130>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x264(%rbp)
jmp    128f <boithoad_sidToGroup+0x11f>
mov    -0x18(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x264(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x264(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<boithoad_sidToGroup>:
push   %rbp
push   %r14
push   %rbx
sub    $0x250,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0x50(%rsp),%rdi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    0xe69(%rip),%rdi
mov    $0xda3,%esi
call   1090 <cconnect@plt>
test   %eax,%eax
je     1222 <boithoad_sidToGroup+0xb2>
mov    %eax,%ebp
lea    0xe5b(%rip),%r9
xor    %ebx,%ebx
mov    %eax,%edi
mov    $0x29,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <sendpacked@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1070 <sendall@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1060 <recvall@plt>
test   %eax,%eax
je     123e <boithoad_sidToGroup+0xce>
cmpl   $0x1,0xc(%rsp)
jne    1226 <boithoad_sidToGroup+0xb6>
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
mov    $0x40,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1060 <recvall@plt>
test   %eax,%eax
je     123e <boithoad_sidToGroup+0xce>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%ebx
jmp    1237 <boithoad_sidToGroup+0xc7>
xor    %ebx,%ebx
jmp    123e <boithoad_sidToGroup+0xce>
lea    0xddc(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x250,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @boithoad_sidToGroup(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = alloca [512 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 [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = call i32 @strncpy(i8* %8, i8* %0, i32 512)
%10 = call i32 @cconnect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 3491)
%11 = icmp eq i32 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %2
%13 = call i32 @sendpacked(i32 %10, i32 41, i32 1, i32 0, i32* null, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @sendall(i32 %10, i8* %8, i32 512)
%15 = call i32 (i32, ...) @recvall(i32 %10, i32* %3, i64 4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %12
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = call i32 (i32, ...) @recvall(i32 %10, i8* %7, i64 64)
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = call i32 @strcpy(i8* %1, i8* %7)
br label %27
25: ; preds = %17
%26 = call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = phi i32 [ 1, %23 ], [ 0, %25 ]
%29 = call i32 @close(i32 %10)
br label %30
30: ; preds = %20, %12, %2, %27
%31 = phi i32 [ %28, %27 ], [ 0, %2 ], [ 0, %12 ], [ 0, %20 ]
ret i32 %31
}