#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 parser {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ close_serving_thread(struct parser *, struct parser *);
int connect_remote_http(struct parser *, struct parser *);
int forward_request(struct parser *, struct parser *);
struct parser *new_parser(int);
int parse_request(struct parser *);
int /*<<< orphan*/ parser_reset(struct parser *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void *serve_request(void *p) {
  int sockfd = *((int *)p);
  struct parser *req = new_parser(sockfd);
  struct parser *reply = new_parser(-1);
  if ((parse_request(req) == -1) || (connect_remote_http(req, reply) == -1) ||
      (forward_request(req, reply)) == -1) {
    close_serving_thread(req, reply);
  }
  do {
    parser_reset(req);
    parser_reset(reply);
  } while (parse_request(req) == 0 && forward_request(req, reply) == 0);
  syslog(LOG_INFO, "closed connection");
  close_serving_thread(req, reply);
  return NULL;
}


x86 assembly (clang, -O0):
<serve_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <new_parser@plt>
mov    %rax,-0x18(%rbp)
mov    $0xffffffff,%edi
call   1060 <new_parser@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <parse_request@plt>
cmp    $0xffffffff,%eax
je     11dd <serve_request+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <connect_remote_http@plt>
cmp    $0xffffffff,%eax
je     11dd <serve_request+0x6d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <forward_request@plt>
cmp    $0xffffffff,%eax
jne    11ea <serve_request+0x7a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <close_serving_thread@plt>
jmp    11ef <serve_request+0x7f>
mov    -0x18(%rbp),%rdi
call   1080 <parser_reset@plt>
mov    -0x20(%rbp),%rdi
call   1080 <parser_reset@plt>
mov    -0x18(%rbp),%rdi
call   1090 <parse_request@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    1230 <serve_request+0xc0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <forward_request@plt>
cmp    $0x0,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ef <serve_request+0x7f>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   1070 <syslog@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <close_serving_thread@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serve_request>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%edi
call   1060 <new_parser@plt>
mov    %rax,%rbx
mov    $0xffffffff,%edi
call   1060 <new_parser@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <parse_request@plt>
cmp    $0xffffffff,%eax
je     11b8 <serve_request+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <connect_remote_http@plt>
cmp    $0xffffffff,%eax
je     11b8 <serve_request+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <forward_request@plt>
cmp    $0xffffffff,%eax
jne    11d0 <serve_request+0x60>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <close_serving_thread@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <parser_reset@plt>
mov    %r14,%rdi
call   1080 <parser_reset@plt>
mov    %rbx,%rdi
call   1090 <parse_request@plt>
test   %eax,%eax
jne    11fb <serve_request+0x8b>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <forward_request@plt>
test   %eax,%eax
je     11d0 <serve_request+0x60>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
call   1070 <syslog@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <close_serving_thread@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.parser = type { i32 }
@LOG_INFO = global i32 0
@.str = [18 x i8] c"closed connection\00"
define i8* @serve_request(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.parser*
%5 = alloca %struct.parser*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call %struct.parser* @new_parser(i32 %9)
store %struct.parser* %10, %struct.parser** %4
%11 = call %struct.parser* @new_parser(i32 -1)
store %struct.parser* %11, %struct.parser** %5
%12 = load %struct.parser*, %struct.parser** %4
%13 = call i32 @parse_request(%struct.parser* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %25, label %15
15: ; preds = %1
%16 = load %struct.parser*, %struct.parser** %4
%17 = load %struct.parser*, %struct.parser** %5
%18 = call i32 @connect_remote_http(%struct.parser* %16, %struct.parser* %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load %struct.parser*, %struct.parser** %4
%22 = load %struct.parser*, %struct.parser** %5
%23 = call i32 @forward_request(%struct.parser* %21, %struct.parser* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %29
25: ; preds = %20, %15, %1
%26 = load %struct.parser*, %struct.parser** %4
%27 = load %struct.parser*, %struct.parser** %5
%28 = call i32 @close_serving_thread(%struct.parser* %26, %struct.parser* %27)
br label %29
29: ; preds = %25, %20
br label %30
30: ; preds = %44, %29
%31 = load %struct.parser*, %struct.parser** %4
%32 = call i32 @parser_reset(%struct.parser* %31)
%33 = load %struct.parser*, %struct.parser** %5
%34 = call i32 @parser_reset(%struct.parser* %33)
br label %35
35: ; preds = %30
%36 = load %struct.parser*, %struct.parser** %4
%37 = call i32 @parse_request(%struct.parser* %36)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load %struct.parser*, %struct.parser** %4
%41 = load %struct.parser*, %struct.parser** %5
%42 = call i32 @forward_request(%struct.parser* %40, %struct.parser* %41)
%43 = icmp eq i32 %42, 0
br label %44
44: ; preds = %39, %35
%45 = phi i1 [ false, %35 ], [ %43, %39 ]
br i1 %45, label %30, label %46
46: ; preds = %44
%47 = load i32, i32* @LOG_INFO
%48 = call i32 @syslog(i32 %47, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%49 = load %struct.parser*, %struct.parser** %4
%50 = load %struct.parser*, %struct.parser** %5
%51 = call i32 @close_serving_thread(%struct.parser* %49, %struct.parser* %50)
ret i8* null
}

LLVM IR (-O2):
%struct.parser = type { i32 }
@LOG_INFO = global i32 0
@.str = [18 x i8] c"closed connection\00"
define noalias i8* @serve_request(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call %struct.parser* @new_parser(i32 %3)
%5 = tail call %struct.parser* @new_parser(i32 -1)
%6 = tail call i32 @parse_request(%struct.parser* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = tail call i32 @connect_remote_http(%struct.parser* %4, %struct.parser* %5)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @forward_request(%struct.parser* %4, %struct.parser* %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %11, %8, %1
%15 = tail call i32 @close_serving_thread(%struct.parser* %4, %struct.parser* %5)
br label %16
16: ; preds = %14, %11
br label %17
17: ; preds = %16, %22
%18 = tail call i32 @parser_reset(%struct.parser* %4)
%19 = tail call i32 @parser_reset(%struct.parser* %5)
%20 = tail call i32 @parse_request(%struct.parser* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @forward_request(%struct.parser* %4, %struct.parser* %5)
%24 = icmp eq i32 %23, 0
br i1 %24, label %17, label %25
25: ; preds = %17, %22
%26 = load i32, i32* @LOG_INFO
%27 = tail call i32 @syslog(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @close_serving_thread(%struct.parser* %4, %struct.parser* %5)
ret i8* null
}