#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_CLOEXEC;
int accept4(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ recv_alnum(int, char *, int, int);
int /*<<< orphan*/ send_all(int, char const *, int /*<<< orphan*/, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char const *);
void handle_https_factory(int listen_fd) {
  int fd = accept4(listen_fd, NULL, NULL, SOCK_CLOEXEC);
  char instance[(64 + 1)];
  const char *result;
  ;
  if (fd < 0)
    err(EXIT_FAILURE, "accept connection to https-factory.sock");
  ;
  if (!recv_alnum(fd, instance, sizeof instance, 10 * 1000000))
    errx(EXIT_FAILURE, "failed to read instance name");
  ;
  if (strcmp(
          instance,
          "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") ==
      0)
    result = "done";
  else
    result = "fail";
  ;
  if (!send_all(fd, result, strlen(result), 10 * 1000000))
    errx(EXIT_FAILURE, "failed to write https-factory.sock response");
  ;
  close(fd);
}


x86 assembly (clang, -O0):
<handle_https_factory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1040 <accept4@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c5 <handle_https_factory+0x45>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1080 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x41,%edx
mov    $0x989680,%ecx
call   10a0 <recv_alnum@plt>
cmp    $0x0,%eax
jne    11f9 <handle_https_factory+0x79>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1050 <errx@plt>
lea    -0x50(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1223 <handle_https_factory+0xa3>
lea    0xe6c(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    122e <handle_https_factory+0xae>
lea    0xe61(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
mov    $0x989680,%ecx
call   1090 <send_all@plt>
cmp    $0x0,%eax
jne    1276 <handle_https_factory+0xf6>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1050 <errx@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_https_factory>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    0x2e63(%rip),%rax
mov    (%rax),%ecx
xor    %esi,%esi
xor    %edx,%edx
call   1040 <accept4@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11b3 <handle_https_factory+0x33>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1080 <err@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x41,%edx
mov    $0x989680,%ecx
call   10a0 <recv_alnum@plt>
test   %eax,%eax
jne    11e0 <handle_https_factory+0x60>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1050 <errx@plt>
lea    0xe5e(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xe8d(%rip),%rax
lea    0xe8b(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    $0x989680,%ecx
call   1090 <send_all@plt>
test   %eax,%eax
jne    1236 <handle_https_factory+0xb6>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1050 <errx@plt>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SOCK_CLOEXEC = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [40 x i8] c"accept connection to https-factory.sock\00"
@.str.1 = [29 x i8] c"failed to read instance name\00"
@.str.2 = [65 x i8] c"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\00"
@.str.3 = [5 x i8] c"done\00"
@.str.4 = [5 x i8] c"fail\00"
@.str.5 = [44 x i8] c"failed to write https-factory.sock response\00"
define void @handle_https_factory(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [65 x i8]
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* @SOCK_CLOEXEC
%8 = call i32 @accept4(i32 %6, i32* null, i32* null, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @err(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %11, %1
%15 = load i32, i32* %3
%16 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%17 = call i32 @recv_alnum(i32 %15, i8* %16, i32 65, i32 10000000)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @errx(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %14
%23 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %28
27: ; preds = %22
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %5
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
%30 = load i8*, i8** %5
%31 = load i8*, i8** %5
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @send_all(i32 %29, i8* %30, i32 %32, i32 10000000)
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %28
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @errx(i32 %36, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %35, %28
%39 = load i32, i32* %3
%40 = call i32 @close(i32 %39)
ret void
}

LLVM IR (-O2):
@SOCK_CLOEXEC = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [40 x i8] c"accept connection to https-factory.sock\00"
@.str.1 = [29 x i8] c"failed to read instance name\00"
@.str.2 = [65 x i8] c"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\00"
@.str.3 = [5 x i8] c"done\00"
@.str.4 = [5 x i8] c"fail\00"
@.str.5 = [44 x i8] c"failed to write https-factory.sock response\00"
define void @handle_https_factory(i32 %0) {
%2 = alloca [65 x i8]
%3 = load i32, i32* @SOCK_CLOEXEC
%4 = tail call i32 @accept4(i32 %0, i32* null, i32* null, i32 %3)
%5 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%6 = icmp slt i32 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @err(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = call i32 @recv_alnum(i32 %4, i8* %5, i32 65, i32 10000000)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @errx(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @send_all(i32 %4, i8* %19, i32 %20, i32 10000000)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @errx(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %23, %16
%27 = call i32 @close(i32 %4)
ret void
}