#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 ssize_t;
typedef int /*<<< orphan*/ request;

/* Variables and functions */
int /*<<< orphan*/ LOG_DEBUG;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ wdctl_reset(int, char *);
int /*<<< orphan*/ wdctl_restart(int);
int /*<<< orphan*/ wdctl_status(int);
int /*<<< orphan*/ wdctl_stop(int);
void *thread_wdctl_handler(void *arg) {
  int fd, done, i;
  char request[4096];
  ssize_t read_bytes, len;
  _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/"
         "wdctl_thread.c",
         154, LOG_DEBUG, "Entering thread_wdctl_handler....");
  fd = (int)arg;
  _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/"
         "wdctl_thread.c",
         158, LOG_DEBUG, "Read bytes and stuff from %d", fd);
  read_bytes = 0;
  done = 0;
  memset(request, 0, sizeof(request));
  while (!done && read_bytes < (sizeof(request) - 1)) {
    len = read(fd, request + read_bytes, sizeof(request) - read_bytes);
    for (i = read_bytes; i < (read_bytes + len); i++) {
      if (request[i] == '\r' || request[i] == '\n') {
        request[i] = '\0';
        done = 1;
      }
    }
    read_bytes += len;
  }
  if (strncmp(request, "status", 6) == 0) {
    wdctl_status(fd);
  } else if (strncmp(request, "stop", 4) == 0) {
    wdctl_stop(fd);
  } else if (strncmp(request, "reset", 5) == 0) {
    wdctl_reset(fd, (request + 6));
  } else if (strncmp(request, "restart", 7) == 0) {
    wdctl_restart(fd);
  }
  if (!done) {
    _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/"
           "wdctl_thread.c",
           193, LOG_ERR, "Invalid wdctl request.");
    shutdown(fd, 2);
    close(fd);
    pthread_exit(NULL);
  }
  _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/"
         "wdctl_thread.c",
         199, LOG_DEBUG, "Request received: [%s]", request);
  shutdown(fd, 2);
  close(fd);
  _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
         "2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/"
         "wdctl_thread.c",
         203, LOG_DEBUG, "Exiting thread_wdctl_handler....");
  return NULL;
}


x86 assembly (clang, -O0):
<thread_wdctl_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
lea    0xe31(%rip),%rdi
mov    $0x9a,%esi
lea    0xeb6(%rip),%rcx
mov    $0x0,%al
call   10a0 <_debug@plt>
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    -0xc(%rbp),%r8d
lea    0xe03(%rip),%rdi
mov    $0x9e,%esi
lea    0xeaa(%rip),%rcx
mov    $0x0,%al
call   10a0 <_debug@plt>
movl   $0x0,-0x1024(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x1029(%rbp)
jne    125c <thread_wdctl_handler+0xac>
movslq -0x1024(%rbp),%rax
cmp    $0xfff,%rax
setb   %al
mov    %al,-0x1029(%rbp)
mov    -0x1029(%rbp),%al
test   $0x1,%al
jne    126f <thread_wdctl_handler+0xbf>
jmp    1326 <thread_wdctl_handler+0x176>
mov    -0xc(%rbp),%edi
lea    -0x1020(%rbp),%rsi
movslq -0x1024(%rbp),%rax
add    %rax,%rsi
movslq -0x1024(%rbp),%rcx
mov    $0x1000,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1080 <read@plt>
mov    %eax,-0x1028(%rbp)
mov    -0x1024(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1024(%rbp),%ecx
add    -0x1028(%rbp),%ecx
cmp    %ecx,%eax
jge    130f <thread_wdctl_handler+0x15f>
movslq -0x14(%rbp),%rax
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
je     12e9 <thread_wdctl_handler+0x139>
movslq -0x14(%rbp),%rax
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12fc <thread_wdctl_handler+0x14c>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
movl   $0x1,-0x10(%rbp)
jmp    1301 <thread_wdctl_handler+0x151>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12a8 <thread_wdctl_handler+0xf8>
mov    -0x1028(%rbp),%eax
add    -0x1024(%rbp),%eax
mov    %eax,-0x1024(%rbp)
jmp    1234 <thread_wdctl_handler+0x84>
lea    -0x1020(%rbp),%rdi
lea    0xd9c(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1355 <thread_wdctl_handler+0x1a5>
mov    -0xc(%rbp),%edi
call   10d0 <wdctl_status@plt>
jmp    13f7 <thread_wdctl_handler+0x247>
lea    -0x1020(%rbp),%rdi
lea    0xd74(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1384 <thread_wdctl_handler+0x1d4>
mov    -0xc(%rbp),%edi
call   1040 <wdctl_stop@plt>
jmp    13f2 <thread_wdctl_handler+0x242>
lea    -0x1020(%rbp),%rdi
lea    0xd4a(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13be <thread_wdctl_handler+0x20e>
mov    -0xc(%rbp),%edi
lea    -0x1020(%rbp),%rsi
add    $0x6,%rsi
call   1090 <wdctl_reset@plt>
jmp    13ed <thread_wdctl_handler+0x23d>
lea    -0x1020(%rbp),%rdi
lea    0xd16(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13e8 <thread_wdctl_handler+0x238>
mov    -0xc(%rbp),%edi
call   10c0 <wdctl_restart@plt>
jmp    13ed <thread_wdctl_handler+0x23d>
jmp    13f2 <thread_wdctl_handler+0x242>
jmp    13f7 <thread_wdctl_handler+0x247>
cmpl   $0x0,-0x10(%rbp)
jne    1442 <thread_wdctl_handler+0x292>
mov    0x2bc8(%rip),%rax
mov    (%rax),%edx
lea    0xbef(%rip),%rdi
mov    $0xc1,%esi
lea    0xccd(%rip),%rcx
mov    $0x0,%al
call   10a0 <_debug@plt>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <pthread_exit@plt>
mov    0x2b97(%rip),%rax
mov    (%rax),%edx
lea    -0x1020(%rbp),%r8
lea    0xba7(%rip),%rdi
mov    $0xc7,%esi
lea    0xc9c(%rip),%rcx
mov    $0x0,%al
call   10a0 <_debug@plt>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    0x2b58(%rip),%rax
mov    (%rax),%edx
lea    0xb6f(%rip),%rdi
mov    $0xcb,%esi
lea    0xc7b(%rip),%rcx
mov    $0x0,%al
call   10a0 <_debug@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_wdctl_handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r12
mov    0x2e15(%rip),%r15
mov    (%r15),%edx
lea    0xe2b(%rip),%r14
lea    0xeb5(%rip),%rcx
xor    %r13d,%r13d
mov    %r14,%rdi
mov    $0x9a,%esi
xor    %eax,%eax
call   10a0 <_debug@plt>
mov    (%r15),%edx
lea    0xebb(%rip),%rcx
mov    %r14,%rdi
mov    $0x9e,%esi
mov    %r12d,%r8d
xor    %eax,%eax
call   10a0 <_debug@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
nopl   0x0(%rax)
mov    %r13d,%ebx
lea    (%rsp,%rbx,1),%rsi
mov    $0x1000,%edx
sub    %r13d,%edx
mov    %r12d,%edi
call   1080 <read@plt>
add    %eax,%r13d
mov    $0x0,%ebp
test   %eax,%eax
jle    1280 <thread_wdctl_handler+0xd0>
movslq %r13d,%rax
xor    %ebp,%ebp
jmp    1262 <thread_wdctl_handler+0xb2>
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%rsp,%rbx,1)
mov    $0x1,%ebp
add    $0x1,%rbx
cmp    %rax,%rbx
jge    1280 <thread_wdctl_handler+0xd0>
movzbl (%rsp,%rbx,1),%ecx
cmp    $0xd,%cl
je     1250 <thread_wdctl_handler+0xa0>
cmp    $0xa,%cl
je     1250 <thread_wdctl_handler+0xa0>
jmp    1259 <thread_wdctl_handler+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %ebp,%ebp
jne    128d <thread_wdctl_handler+0xdd>
cmp    $0xffe,%r13d
jbe    1220 <thread_wdctl_handler+0x70>
lea    0xe3c(%rip),%rsi
mov    %rsp,%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1303 <thread_wdctl_handler+0x153>
lea    0xe2a(%rip),%rsi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1311 <thread_wdctl_handler+0x161>
lea    0xe16(%rip),%rsi
mov    %rsp,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13c1 <thread_wdctl_handler+0x211>
lea    0xdff(%rip),%rsi
mov    %rsp,%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1319 <thread_wdctl_handler+0x169>
mov    %r12d,%edi
call   10c0 <wdctl_restart@plt>
test   %ebp,%ebp
jne    135c <thread_wdctl_handler+0x1ac>
jmp    131d <thread_wdctl_handler+0x16d>
mov    %r12d,%edi
call   10d0 <wdctl_status@plt>
test   %ebp,%ebp
jne    135c <thread_wdctl_handler+0x1ac>
jmp    131d <thread_wdctl_handler+0x16d>
mov    %r12d,%edi
call   1040 <wdctl_stop@plt>
test   %ebp,%ebp
jne    135c <thread_wdctl_handler+0x1ac>
mov    0x2cac(%rip),%rax
mov    (%rax),%edx
lea    0xcd3(%rip),%rdi
lea    0xdb6(%rip),%rcx
mov    $0xc1,%esi
xor    %eax,%eax
call   10a0 <_debug@plt>
mov    %r12d,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10b0 <pthread_exit@plt>
mov    (%r15),%edx
lea    0xc9a(%rip),%r14
lea    0xd94(%rip),%rcx
mov    %rsp,%r8
mov    %r14,%rdi
mov    $0xc7,%esi
xor    %eax,%eax
call   10a0 <_debug@plt>
mov    %r12d,%edi
mov    $0x2,%esi
call   1050 <shutdown@plt>
mov    %r12d,%edi
call   1070 <close@plt>
mov    (%r15),%edx
lea    0xd7a(%rip),%rcx
mov    %r14,%rdi
mov    $0xcb,%esi
xor    %eax,%eax
call   10a0 <_debug@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x6(%rsp),%rsi
mov    %r12d,%edi
call   1090 <wdctl_reset@plt>
test   %ebp,%ebp
jne    135c <thread_wdctl_handler+0x1ac>
jmp    131d <thread_wdctl_handler+0x16d>

LLVM IR (-O0):
@.str = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/wdctl_thread.c\00"
@LOG_DEBUG = global i32 0
@.str.1 = [34 x i8] c"Entering thread_wdctl_handler....\00"
@.str.2 = [29 x i8] c"Read bytes and stuff from %d\00"
@.str.3 = [7 x i8] c"status\00"
@.str.4 = [5 x i8] c"stop\00"
@.str.5 = [6 x i8] c"reset\00"
@.str.6 = [8 x i8] c"restart\00"
@LOG_ERR = global i32 0
@.str.7 = [23 x i8] c"Invalid wdctl request.\00"
@.str.8 = [23 x i8] c"Request received: [%s]\00"
@.str.9 = [33 x i8] c"Exiting thread_wdctl_handler....\00"
define i8* @thread_wdctl_handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i32, i32* @LOG_DEBUG
%10 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 154, i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = ptrtoint i8* %11 to i32
store i32 %12, i32* %3
%13 = load i32, i32* @LOG_DEBUG
%14 = load i32, i32* %3
%15 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 158, i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 0, i32* %7
store i32 0, i32* %4
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 4096)
br label %18
18: ; preds = %67, %1
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = icmp ult i64 %23, 4095
br label %25
25: ; preds = %21, %18
%26 = phi i1 [ false, %18 ], [ %24, %21 ]
br i1 %26, label %27, label %71
27: ; preds = %25
%28 = load i32, i32* %3
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = sub i64 4096, %34
%36 = trunc i64 %35 to i32
%37 = call i32 @read(i32 %28, i8* %32, i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %7
store i32 %38, i32* %5
br label %39
39: ; preds = %64, %27
%40 = load i32, i32* %5
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = add nsw i32 %41, %42
%44 = icmp slt i32 %40, %43
br i1 %44, label %45, label %67
45: ; preds = %39
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 13
br i1 %51, label %59, label %52
52: ; preds = %45
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %63
59: ; preds = %52, %45
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %61
store i8 0, i8* %62
store i32 1, i32* %4
br label %63
63: ; preds = %59, %52
br label %64
64: ; preds = %63
%65 = load i32, i32* %5
%66 = add nsw i32 %65, 1
store i32 %66, i32* %5
br label %39
67: ; preds = %39
%68 = load i32, i32* %8
%69 = load i32, i32* %7
%70 = add nsw i32 %69, %68
store i32 %70, i32* %7
br label %18
71: ; preds = %25
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%73 = call i64 @strncmp(i8* %72, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load i32, i32* %3
%77 = call i32 @wdctl_status(i32 %76)
br label %104
78: ; preds = %71
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%80 = call i64 @strncmp(i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i32, i32* %3
%84 = call i32 @wdctl_stop(i32 %83)
br label %103
85: ; preds = %78
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%87 = call i64 @strncmp(i8* %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %85
%90 = load i32, i32* %3
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%92 = getelementptr inbounds i8, i8* %91, i64 6
%93 = call i32 @wdctl_reset(i32 %90, i8* %92)
br label %102
94: ; preds = %85
%95 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%96 = call i64 @strncmp(i8* %95, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = load i32, i32* %3
%100 = call i32 @wdctl_restart(i32 %99)
br label %101
101: ; preds = %98, %94
br label %102
102: ; preds = %101, %89
br label %103
103: ; preds = %102, %82
br label %104
104: ; preds = %103, %75
%105 = load i32, i32* %4
%106 = icmp ne i32 %105, 0
br i1 %106, label %115, label %107
107: ; preds = %104
%108 = load i32, i32* @LOG_ERR
%109 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 193, i32 %108, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%110 = load i32, i32* %3
%111 = call i32 @shutdown(i32 %110, i32 2)
%112 = load i32, i32* %3
%113 = call i32 @close(i32 %112)
%114 = call i32 @pthread_exit(i32* null)
br label %115
115: ; preds = %107, %104
%116 = load i32, i32* @LOG_DEBUG
%117 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%118 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 199, i32 %116, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %3
%120 = call i32 @shutdown(i32 %119, i32 2)
%121 = load i32, i32* %3
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* @LOG_DEBUG
%124 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 203, i32 %123, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
@.str = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ForgotFun/wifidog/refs/heads/master/src/wdctl_thread.c\00"
@LOG_DEBUG = global i32 0
@.str.1 = [34 x i8] c"Entering thread_wdctl_handler....\00"
@.str.2 = [29 x i8] c"Read bytes and stuff from %d\00"
@.str.3 = [7 x i8] c"status\00"
@.str.4 = [5 x i8] c"stop\00"
@.str.5 = [6 x i8] c"reset\00"
@.str.6 = [8 x i8] c"restart\00"
@LOG_ERR = global i32 0
@.str.7 = [23 x i8] c"Invalid wdctl request.\00"
@.str.8 = [23 x i8] c"Request received: [%s]\00"
@.str.9 = [33 x i8] c"Exiting thread_wdctl_handler....\00"
define noalias i8* @thread_wdctl_handler(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @LOG_DEBUG
%5 = tail call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 154, i32 %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%6 = ptrtoint i8* %0 to i64
%7 = trunc i64 %6 to i32
%8 = load i32, i32* @LOG_DEBUG
%9 = tail call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 158, i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%10 = call i32 @memset(i8* %3, i32 0, i32 4096)
br label %16
11: ; preds = %33, %16
%12 = phi i32 [ 0, %16 ], [ %34, %33 ]
%13 = icmp eq i32 %12, 0
%14 = icmp ult i32 %22, 4095
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %37
16: ; preds = %1, %11
%17 = phi i32 [ 0, %1 ], [ %22, %11 ]
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %18
%20 = sub nuw nsw i32 4096, %17
%21 = call i32 @read(i32 %7, i8* %19, i32 %20)
%22 = add nsw i32 %21, %17
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %11
24: ; preds = %16
%25 = zext i32 %17 to i64
%26 = sext i32 %22 to i64
br label %27
27: ; preds = %24, %33
%28 = phi i64 [ %25, %24 ], [ %35, %33 ]
%29 = phi i32 [ 0, %24 ], [ %34, %33 ]
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %28
%31 = load i8, i8* %30
switch i8 %31, label %33 [
i8 13, label %32
i8 10, label %32
]
32: ; preds = %27, %27
store i8 0, i8* %30
br label %33
33: ; preds = %27, %32
%34 = phi i32 [ 1, %32 ], [ %29, %27 ]
%35 = add nuw nsw i64 %28, 1
%36 = icmp slt i64 %35, %26
br i1 %36, label %27, label %11
37: ; preds = %11
%38 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @wdctl_status(i32 %7)
br label %58
42: ; preds = %37
%43 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @wdctl_stop(i32 %7)
br label %58
47: ; preds = %42
%48 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 6
%52 = call i32 @wdctl_reset(i32 %7, i8* %51)
br label %58
53: ; preds = %47
%54 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 @wdctl_restart(i32 %7)
br label %58
58: ; preds = %45, %53, %56, %50, %40
br i1 %13, label %59, label %65
59: ; preds = %58
%60 = load i32, i32* @LOG_ERR
%61 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 193, i32 %60, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%62 = call i32 @shutdown(i32 %7, i32 2)
%63 = call i32 @close(i32 %7)
%64 = call i32 @pthread_exit(i32* null)
br label %65
65: ; preds = %59, %58
%66 = load i32, i32* @LOG_DEBUG
%67 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 199, i32 %66, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%68 = call i32 @shutdown(i32 %7, i32 2)
%69 = call i32 @close(i32 %7)
%70 = load i32, i32* @LOG_DEBUG
%71 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 203, i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
ret i8* null
}