#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int SOCK_NONBLOCK;
int SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(int, char *);
int /*<<< orphan*/ error_d(int, char *, char *);
int /*<<< orphan*/ getCmd(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i, n, sockfd, servlen;
  char buffer[1024];
  struct sockaddr_un serv_addr;
  struct timeval tstart, tnow;
  getCmd(buffer);
  if (buffer[0] == '\0')
    error(400, "Missing Command");
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sun_family = AF_UNIX;
  strcpy(serv_addr.sun_path, "/tmp/btsock");
  servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
  if ((sockfd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) < 0)
    error(500, "Unable to create socket");
  if (connect(sockfd, (struct sockaddr *)&serv_addr, servlen) < 0)
    error(500, "Unable to connect to socket");
  write(sockfd, buffer, strlen(buffer));
  (void)gettimeofday(&tstart, NULL);
  n = 0;
  while (n < 1024) {
    i = read(sockfd, buffer + n, 1024 - n);
    if (i > 0) {
      n += i;
      if (buffer[n - 1] == '\n')
        break;
      buffer[n] = '\0';
    }
    (void)gettimeofday(&tnow, NULL);
    if ((tnow.tv_sec * 1000 + tnow.tv_usec / 1000) -
            (tstart.tv_sec * 1000 + tstart.tv_usec / 1000) >=
        5000)
      error_d(500, "Response Timeout", buffer);
  }
  close(sockfd);
  if (n == 1024)
    error(500, "Response Overflow");
  char *cmdField = strchr(buffer, '\t');
  if (cmdField == NULL)
    error(500, "Unexpected Response");
  cmdField++;
  if (strchr(cmdField, '\t') == NULL)
    error(500, "Missing Data");
  if (cmdField[0] == '!')
    error(400, "Invalid Command");
  if (cmdField[0] == '#')
    error(400, "Parameter Count Mismatch");
  printf("Access-Control-Allow-Origin: *\r\nContent-Type: text/html\r\n\r\n");
  printf("[\"");
  for (i = 0; i < n; i++) {
    if (buffer[i] == '\t')
      printf("\",\"");
    else if (buffer[i] == '\r') {
    } else if (buffer[i] == '\n') {
      printf("\"]\n");
      break;
    } else
      putchar(buffer[i]);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x420(%rbp),%rdi
call   10e0 <getCmd@plt>
movsbl -0x420(%rbp),%eax
cmp    $0x0,%eax
jne    122f <main+0x3f>
mov    $0x190,%edi
lea    0xdd6(%rip),%rsi
call   10c0 <error@plt>
lea    -0x430(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    -0x430(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x430(%rbp),%rdi
call   1060 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x14(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
mov    0x2d48(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    12b6 <main+0xc6>
mov    $0x1f4,%edi
lea    0xd6b(%rip),%rsi
call   10c0 <error@plt>
mov    -0x10(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    12e3 <main+0xf3>
mov    $0x1f4,%edi
lea    0xd56(%rip),%rsi
call   10c0 <error@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    -0x438(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x400,-0xc(%rbp)
jge    1426 <main+0x236>
mov    -0x10(%rbp),%edi
lea    -0x420(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    $0x400,%edx
sub    -0xc(%rbp),%edx
call   10b0 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    139c <main+0x1ac>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1390 <main+0x1a0>
jmp    1426 <main+0x236>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x440(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
imul   $0x3e8,-0x440(%rbp),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x43c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x45c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x458(%rbp)
imul   $0x3e8,-0x438(%rbp),%ecx
mov    -0x434(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x458(%rbp),%eax
add    %edx,%ecx
sub    %ecx,%eax
cmp    $0x1388,%eax
jl     1421 <main+0x231>
lea    -0x420(%rbp),%rdx
mov    $0x1f4,%edi
lea    0xc34(%rip),%rsi
call   1100 <error_d@plt>
jmp    1331 <main+0x141>
mov    -0x10(%rbp),%edi
call   10a0 <close@plt>
cmpl   $0x400,-0xc(%rbp)
jne    144c <main+0x25c>
mov    $0x1f4,%edi
lea    0xc1a(%rip),%rsi
call   10c0 <error@plt>
lea    -0x420(%rbp),%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    1483 <main+0x293>
mov    $0x1f4,%edi
lea    0xbf5(%rip),%rsi
call   10c0 <error@plt>
mov    -0x448(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rdi
mov    $0x9,%esi
call   1070 <strchr@plt>
cmp    $0x0,%rax
jne    14c1 <main+0x2d1>
mov    $0x1f4,%edi
lea    0xbcb(%rip),%rsi
call   10c0 <error@plt>
mov    -0x448(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
jne    14e5 <main+0x2f5>
mov    $0x190,%edi
lea    0xbb4(%rip),%rsi
call   10c0 <error@plt>
mov    -0x448(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1509 <main+0x319>
mov    $0x190,%edi
lea    0xba0(%rip),%rsi
call   10c0 <error@plt>
lea    0xbad(%rip),%rdi
call   1080 <printf@plt>
lea    0xbdd(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    15c8 <main+0x3d8>
movslq -0x8(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x9,%eax
jne    155a <main+0x36a>
lea    0xbac(%rip),%rdi
call   1080 <printf@plt>
jmp    15b5 <main+0x3c5>
movslq -0x8(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    1574 <main+0x384>
jmp    15b0 <main+0x3c0>
movslq -0x8(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    159a <main+0x3aa>
lea    0xb70(%rip),%rdi
call   1080 <printf@plt>
jmp    15c8 <main+0x3d8>
movslq -0x8(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
jmp    15b0 <main+0x3c0>
jmp    15b5 <main+0x3c5>
jmp    15ba <main+0x3ca>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1528 <main+0x338>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   10f0 <getCmd@plt>
cmpb   $0x0,0x20(%rsp)
jne    1236 <main+0x36>
lea    0xdd4(%rip),%rsi
mov    $0x190,%edi
call   10d0 <error@plt>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   10e0 <bzero@plt>
mov    0x2d9c(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rsp),%rbx
lea    0xdb1(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
add    $0x4,%ebx
mov    0x0(%rbp),%edi
mov    0x2d52(%rip),%rax
mov    0x2d53(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    12a8 <main+0xa8>
lea    0xd7e(%rip),%rsi
mov    $0x1f4,%edi
call   10d0 <error@plt>
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    %ebx,%edx
call   1100 <connect@plt>
test   %rax,%rax
jns    12cd <main+0xcd>
lea    0xd71(%rip),%rsi
mov    $0x1f4,%edi
call   10d0 <error@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <write@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   10a0 <gettimeofday@plt>
mov    0x8(%rsp),%ebp
movslq 0xc(%rsp),%rax
imul   $0xffffffffef9db22d,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x26,%r15
add    %eax,%r15d
mov    %rsp,%r12
jmp    132c <main+0x12c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x400,%ebx
jge    13af <main+0x1af>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x20,%rsi
mov    $0x400,%edx
sub    %eax,%edx
mov    %r13d,%edi
call   10c0 <read@plt>
test   %eax,%eax
jle    135c <main+0x15c>
add    %eax,%ebx
movslq %ebx,%rax
cmpb   $0xa,-0x1(%rax,%r14,1)
je     13af <main+0x1af>
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <gettimeofday@plt>
mov    (%rsp),%eax
sub    %ebp,%eax
movslq 0x4(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %r15d,%ecx
imul   $0x3e8,%eax,%eax
add    %ecx,%eax
cmp    $0x1388,%eax
jl     1320 <main+0x120>
mov    $0x1f4,%edi
lea    0xcae(%rip),%rsi
mov    %r14,%rdx
call   1110 <error_d@plt>
jmp    1320 <main+0x120>
mov    %r13d,%edi
call   10b0 <close@plt>
cmp    $0x400,%ebx
jne    13d0 <main+0x1d0>
lea    0xc9b(%rip),%rsi
mov    $0x1f4,%edi
call   10d0 <error@plt>
lea    0x20(%rsp),%rdi
mov    $0x9,%esi
call   1080 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    13f8 <main+0x1f8>
lea    0xc85(%rip),%rsi
mov    $0x1f4,%edi
call   10d0 <error@plt>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x9,%esi
call   1080 <strchr@plt>
test   %rax,%rax
jne    141f <main+0x21f>
lea    0xc72(%rip),%rsi
mov    $0x1f4,%edi
call   10d0 <error@plt>
mov    0x0(%rbp),%al
cmp    $0x21,%al
jne    143a <main+0x23a>
lea    0xc67(%rip),%rsi
mov    $0x190,%edi
call   10d0 <error@plt>
mov    0x0(%rbp),%al
cmp    $0x23,%al
jne    144f <main+0x24f>
lea    0xc5f(%rip),%rsi
mov    $0x190,%edi
call   10d0 <error@plt>
lea    0xc6e(%rip),%rdi
call   1050 <puts@plt>
lea    0xc5b(%rip),%rdi
call   1090 <printf@plt>
test   %ebx,%ebx
jle    14b8 <main+0x2b8>
mov    %ebx,%ebp
xor    %ebx,%ebx
lea    0xc4a(%rip),%r14
jmp    1491 <main+0x291>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     14b8 <main+0x2b8>
movzbl 0x20(%rsp,%rbx,1),%eax
cmp    $0x9,%al
je     1480 <main+0x280>
cmp    $0xd,%al
je     1488 <main+0x288>
cmp    $0xa,%al
je     14ac <main+0x2ac>
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1488 <main+0x288>
lea    0xc4c(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Missing Command\00"
@AF_UNIX = global i32 0
@.str.1 = [12 x i8] c"/tmp/btsock\00"
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [24 x i8] c"Unable to create socket\00"
@.str.3 = [28 x i8] c"Unable to connect to socket\00"
@.str.4 = [17 x i8] c"Response Timeout\00"
@.str.5 = [18 x i8] c"Response Overflow\00"
@.str.6 = [20 x i8] c"Unexpected Response\00"
@.str.7 = [13 x i8] c"Missing Data\00"
@.str.8 = [16 x i8] c"Invalid Command\00"
@.str.9 = [25 x i8] c"Parameter Count Mismatch\00"
@.str.10 = [60 x i8] c"Access-Control-Allow-Origin: *\0D\0AContent-Type: text/html\0D\0A\0D\0A\00"
@.str.11 = [3 x i8] c"[\22\00"
@.str.12 = [4 x i8] c"\22,\22\00"
@.str.13 = [4 x i8] c"\22]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca %struct.sockaddr_un
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i8*
store i32 0, i32* %1
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = call i32 @getCmd(i8* %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @error(i32 400, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
%20 = bitcast %struct.sockaddr_un* %7 to i8*
%21 = call i32 @bzero(i8* %20, i32 16)
%22 = load i32, i32* @AF_UNIX
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = add i64 %30, 4
%32 = trunc i64 %31 to i32
store i32 %32, i32* %5
%33 = load i32, i32* @AF_UNIX
%34 = load i32, i32* @SOCK_STREAM
%35 = load i32, i32* @SOCK_NONBLOCK
%36 = or i32 %34, %35
%37 = call i32 @socket(i32 %33, i32 %36, i32 0)
store i32 %37, i32* %4
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %19
%40 = call i32 @error(i32 500, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %19
%42 = load i32, i32* %4
%43 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%44 = load i32, i32* %5
%45 = call i64 @connect(i32 %42, %struct.sockaddr* %43, i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @error(i32 500, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %41
%50 = load i32, i32* %4
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @write(i32 %50, i8* %51, i32 %53)
%55 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
store i32 0, i32* %3
br label %56
56: ; preds = %107, %49
%57 = load i32, i32* %3
%58 = icmp slt i32 %57, 1024
br i1 %58, label %59, label %108
59: ; preds = %56
%60 = load i32, i32* %4
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%62 = load i32, i32* %3
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i32, i32* %3
%66 = sub nsw i32 1024, %65
%67 = call i32 @read(i32 %60, i8* %64, i32 %66)
store i32 %67, i32* %2
%68 = load i32, i32* %2
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %86
70: ; preds = %59
%71 = load i32, i32* %2
%72 = load i32, i32* %3
%73 = add nsw i32 %72, %71
store i32 %73, i32* %3
%74 = load i32, i32* %3
%75 = sub nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp eq i32 %79, 10
br i1 %80, label %81, label %82
81: ; preds = %70
br label %108
82: ; preds = %70
%83 = load i32, i32* %3
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %84
store i8 0, i8* %85
br label %86
86: ; preds = %82, %59
%87 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%89 = load i32, i32* %88
%90 = mul nsw i32 %89, 1000
%91 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%92 = load i32, i32* %91
%93 = sdiv i32 %92, 1000
%94 = add nsw i32 %90, %93
%95 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%96 = load i32, i32* %95
%97 = mul nsw i32 %96, 1000
%98 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%99 = load i32, i32* %98
%100 = sdiv i32 %99, 1000
%101 = add nsw i32 %97, %100
%102 = sub nsw i32 %94, %101
%103 = icmp sge i32 %102, 5000
br i1 %103, label %104, label %107
104: ; preds = %86
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%106 = call i32 @error_d(i32 500, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %105)
br label %107
107: ; preds = %104, %86
br label %56
108: ; preds = %81, %56
%109 = load i32, i32* %4
%110 = call i32 @close(i32 %109)
%111 = load i32, i32* %3
%112 = icmp eq i32 %111, 1024
br i1 %112, label %113, label %115
113: ; preds = %108
%114 = call i32 @error(i32 500, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %115
115: ; preds = %113, %108
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%117 = call i8* @strchr(i8* %116, i8 signext 9)
store i8* %117, i8** %10
%118 = load i8*, i8** %10
%119 = icmp eq i8* %118, null
br i1 %119, label %120, label %122
120: ; preds = %115
%121 = call i32 @error(i32 500, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %122
122: ; preds = %120, %115
%123 = load i8*, i8** %10
%124 = getelementptr inbounds i8, i8* %123, i32 1
store i8* %124, i8** %10
%125 = load i8*, i8** %10
%126 = call i8* @strchr(i8* %125, i8 signext 9)
%127 = icmp eq i8* %126, null
br i1 %127, label %128, label %130
128: ; preds = %122
%129 = call i32 @error(i32 500, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %130
130: ; preds = %128, %122
%131 = load i8*, i8** %10
%132 = getelementptr inbounds i8, i8* %131, i64 0
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = icmp eq i32 %134, 33
br i1 %135, label %136, label %138
136: ; preds = %130
%137 = call i32 @error(i32 400, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %138
138: ; preds = %136, %130
%139 = load i8*, i8** %10
%140 = getelementptr inbounds i8, i8* %139, i64 0
%141 = load i8, i8* %140
%142 = sext i8 %141 to i32
%143 = icmp eq i32 %142, 35
br i1 %143, label %144, label %146
144: ; preds = %138
%145 = call i32 @error(i32 400, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %146
146: ; preds = %144, %138
%147 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.10, i64 0, i64 0))
%148 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %2
br label %149
149: ; preds = %188, %146
%150 = load i32, i32* %2
%151 = load i32, i32* %3
%152 = icmp slt i32 %150, %151
br i1 %152, label %153, label %191
153: ; preds = %149
%154 = load i32, i32* %2
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %155
%157 = load i8, i8* %156
%158 = sext i8 %157 to i32
%159 = icmp eq i32 %158, 9
br i1 %159, label %160, label %162
160: ; preds = %153
%161 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
br label %187
162: ; preds = %153
%163 = load i32, i32* %2
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %164
%166 = load i8, i8* %165
%167 = sext i8 %166 to i32
%168 = icmp eq i32 %167, 13
br i1 %168, label %169, label %170
169: ; preds = %162
br label %186
170: ; preds = %162
%171 = load i32, i32* %2
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %172
%174 = load i8, i8* %173
%175 = sext i8 %174 to i32
%176 = icmp eq i32 %175, 10
br i1 %176, label %177, label %179
177: ; preds = %170
%178 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0))
br label %191
179: ; preds = %170
%180 = load i32, i32* %2
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %181
%183 = load i8, i8* %182
%184 = call i32 @putchar(i8 signext %183)
br label %185
185: ; preds = %179
br label %186
186: ; preds = %185, %169
br label %187
187: ; preds = %186, %160
br label %188
188: ; preds = %187
%189 = load i32, i32* %2
%190 = add nsw i32 %189, 1
store i32 %190, i32* %2
br label %149
191: ; preds = %177, %149
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"Missing Command\00"
@AF_UNIX = global i32 0
@.str.1 = [12 x i8] c"/tmp/btsock\00"
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str.2 = [24 x i8] c"Unable to create socket\00"
@.str.3 = [28 x i8] c"Unable to connect to socket\00"
@.str.4 = [17 x i8] c"Response Timeout\00"
@.str.5 = [18 x i8] c"Response Overflow\00"
@.str.6 = [20 x i8] c"Unexpected Response\00"
@.str.7 = [13 x i8] c"Missing Data\00"
@.str.8 = [16 x i8] c"Invalid Command\00"
@.str.9 = [25 x i8] c"Parameter Count Mismatch\00"
@.str.11 = [3 x i8] c"[\22\00"
@.str.12 = [4 x i8] c"\22,\22\00"
@str = [59 x i8] c"Access-Control-Allow-Origin: *\0D\0AContent-Type: text/html\0D\0A\0D\00"
@str.14 = [3 x i8] c"\22]\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_un
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.sockaddr_un* %2 to i8*
%7 = bitcast %struct.timeval* %3 to i8*
%8 = bitcast %struct.timeval* %4 to i8*
%9 = call i32 @getCmd(i8* %5)
%10 = load i8, i8* %5
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @error(i32 400, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = call i32 @bzero(i8* %6, i32 16)
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @strlen(i8* %19)
%22 = add i32 %21, 4
%23 = load i32, i32* @AF_UNIX
%24 = load i32, i32* @SOCK_STREAM
%25 = load i32, i32* @SOCK_NONBLOCK
%26 = or i32 %25, %24
%27 = call i32 @socket(i32 %23, i32 %26, i32 0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %14
%30 = call i32 @error(i32 500, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %14
%32 = bitcast %struct.sockaddr_un* %2 to %struct.sockaddr*
%33 = call i64 @connect(i32 %27, %struct.sockaddr* %32, i32 %22)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @error(i32 500, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = call i32 @strlen(i8* %5)
%39 = call i32 @write(i32 %27, i8* %5, i32 %38)
%40 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%46 = load i32, i32* %45
%47 = sdiv i32 %46, -1000
br label %48
48: ; preds = %37, %78
%49 = phi i32 [ 0, %37 ], [ %66, %78 ]
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %50
%52 = sub nsw i32 1024, %49
%53 = call i32 @read(i32 %27, i8* %51, i32 %52)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %48
%56 = add nsw i32 %53, %49
%57 = add nsw i32 %56, -1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = icmp eq i8 %60, 10
br i1 %61, label %80, label %62
62: ; preds = %55
%63 = sext i32 %56 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %63
store i8 0, i8* %64
br label %65
65: ; preds = %62, %48
%66 = phi i32 [ %56, %62 ], [ %49, %48 ]
%67 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%68 = load i32, i32* %41
%69 = load i32, i32* %42
%70 = sdiv i32 %69, 1000
%71 = sub i32 %68, %44
%72 = mul i32 %71, 1000
%73 = add nsw i32 %47, %70
%74 = add i32 %73, %72
%75 = icmp sgt i32 %74, 4999
br i1 %75, label %76, label %78
76: ; preds = %65
%77 = call i32 @error_d(i32 500, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %78
78: ; preds = %76, %65
%79 = icmp slt i32 %66, 1024
br i1 %79, label %48, label %80
80: ; preds = %55, %78
%81 = phi i32 [ %56, %55 ], [ %66, %78 ]
%82 = call i32 @close(i32 %27)
%83 = icmp eq i32 %81, 1024
br i1 %83, label %84, label %86
84: ; preds = %80
%85 = call i32 @error(i32 500, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %86
86: ; preds = %84, %80
%87 = call i8* @strchr(i8* %5, i8 signext 9)
%88 = icmp eq i8* %87, null
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 @error(i32 500, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %91
91: ; preds = %89, %86
%92 = getelementptr inbounds i8, i8* %87, i64 1
%93 = call i8* @strchr(i8* %92, i8 signext 9)
%94 = icmp eq i8* %93, null
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @error(i32 500, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %97
97: ; preds = %95, %91
%98 = load i8, i8* %92
%99 = icmp eq i8 %98, 33
br i1 %99, label %100, label %103
100: ; preds = %97
%101 = call i32 @error(i32 400, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%102 = load i8, i8* %92
br label %103
103: ; preds = %100, %97
%104 = phi i8 [ %102, %100 ], [ %98, %97 ]
%105 = icmp eq i8 %104, 35
br i1 %105, label %106, label %108
106: ; preds = %103
%107 = call i32 @error(i32 400, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %108
108: ; preds = %106, %103
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%110 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%111 = icmp sgt i32 %81, 0
br i1 %111, label %112, label %127
112: ; preds = %108
%113 = zext i32 %81 to i64
br label %114
114: ; preds = %112, %124
%115 = phi i64 [ 0, %112 ], [ %125, %124 ]
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %115
%117 = load i8, i8* %116
switch i8 %117, label %122 [
i8 9, label %118
i8 13, label %124
i8 10, label %120
]
118: ; preds = %114
%119 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
br label %124
120: ; preds = %114
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.14, i64 0, i64 0))
br label %127
122: ; preds = %114
%123 = call i32 @putchar(i8 signext %117)
br label %124
124: ; preds = %114, %118, %122
%125 = add nuw nsw i64 %115, 1
%126 = icmp eq i64 %125, %113
br i1 %126, label %127, label %114
127: ; preds = %124, %108, %120
ret i32 0
}