#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*/ printf(char *, char *, 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_sidToUser(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, 40, 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 {
    printf("didn't have a user at %s:%d\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/bowlofstew/enterprise-search/refs/heads/"
           "master/src/boithoadClientLib/boithoadClientLib.c",
           296);
    strcpy(username_in, "");
    forreturn = 0;
  }
  close(socketha);
  return forreturn;
}


x86 assembly (clang, -O0):
<boithoad_sidToUser>:
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    0xe47(%rip),%rdi
mov    $0xda3,%esi
call   10a0 <cconnect@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11db <boithoad_sidToUser+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <boithoad_sidToUser+0x148>
mov    -0x1c(%rbp),%edi
mov    $0x28,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
lea    0xe30(%rip),%r9
call   1090 <sendpacked@plt>
mov    -0x1c(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x200,%edx
call   1080 <sendall@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1070 <recvall@plt>
cmp    $0x0,%eax
jne    1237 <boithoad_sidToUser+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <boithoad_sidToUser+0x148>
cmpl   $0x1,-0x20(%rbp)
jne    1285 <boithoad_sidToUser+0x105>
mov    -0x1c(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
mov    $0x0,%al
call   1070 <recvall@plt>
cmp    $0x0,%eax
jne    1269 <boithoad_sidToUser+0xe9>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <boithoad_sidToUser+0x148>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x264(%rbp)
jmp    12b7 <boithoad_sidToUser+0x137>
lea    0xd7e(%rip),%rdi
lea    0xd94(%rip),%rsi
mov    $0x128,%edx
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x264(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <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_sidToUser>:
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    0xe59(%rip),%rdi
mov    $0xda3,%esi
call   10a0 <cconnect@plt>
test   %eax,%eax
je     1232 <boithoad_sidToUser+0xb2>
mov    %eax,%ebp
lea    0xe68(%rip),%r9
xor    %ebx,%ebx
mov    %eax,%edi
mov    $0x28,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <sendpacked@plt>
lea    0x50(%rsp),%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1080 <sendall@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1070 <recvall@plt>
test   %eax,%eax
je     1266 <boithoad_sidToUser+0xe6>
cmpl   $0x1,0xc(%rsp)
jne    1236 <boithoad_sidToUser+0xb6>
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
mov    $0x40,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1070 <recvall@plt>
test   %eax,%eax
je     1266 <boithoad_sidToUser+0xe6>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%ebx
jmp    125f <boithoad_sidToUser+0xdf>
xor    %ebx,%ebx
jmp    1266 <boithoad_sidToUser+0xe6>
lea    0xdcd(%rip),%rdi
lea    0xde3(%rip),%rsi
mov    $0x128,%edx
call   1050 <printf@plt>
lea    0xdd1(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1060 <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
@.str.2 = [29 x i8] c"didn't have a user at %s:%d\0A\00"
@.str.3 = [179 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bowlofstew/enterprise-search/refs/heads/master/src/boithoadClientLib/boithoadClientLib.c\00"
define i32 @boithoad_sidToUser(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 %48
17: ; preds = %2
%18 = load i32, i32* %6
%19 = call i32 @sendpacked(i32 %18, i32 40, 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 %48
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 %48
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 %44
40: ; preds = %27
%41 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.3, i64 0, i64 0), i32 296)
%42 = load i8*, i8** %5
%43 = call i32 @strcpy(i8* %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %10
br label %44
44: ; preds = %40, %36
%45 = load i32, i32* %6
%46 = call i32 @close(i32 %45)
%47 = load i32, i32* %10
store i32 %47, i32* %3
br label %48
48: ; preds = %44, %35, %26, %16
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [29 x i8] c"didn't have a user at %s:%d\0A\00"
@.str.3 = [179 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bowlofstew/enterprise-search/refs/heads/master/src/boithoadClientLib/boithoadClientLib.c\00"
define i32 @boithoad_sidToUser(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 %31, label %12
12: ; preds = %2
%13 = call i32 @sendpacked(i32 %10, i32 40, 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 %31, 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 %31, label %23
23: ; preds = %20
%24 = call i32 @strcpy(i8* %1, i8* %7)
br label %28
25: ; preds = %17
%26 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.3, i64 0, i64 0), i32 296)
%27 = call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %23
%29 = phi i32 [ 1, %23 ], [ 0, %25 ]
%30 = call i32 @close(i32 %10)
br label %31
31: ; preds = %20, %12, %2, %28
%32 = phi i32 [ %29, %28 ], [ 0, %2 ], [ 0, %12 ], [ 0, %20 ]
ret i32 %32
}