#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*/ uint16_t;
struct evhttp_request {
  int dummy;
};
struct evhttp_connection {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ evhttp_connection_free(struct evhttp_connection *);
int /*<<< orphan*/ evhttp_connection_get_peer(struct evhttp_connection *,
                                              char **, int /*<<< orphan*/ *);
int evhttp_request_get_response_code(struct evhttp_request *);
int /*<<< orphan*/ mark_slave_offline(char *, int /*<<< orphan*/);
int /*<<< orphan*/ t01_log(int, char *, char *, int /*<<< orphan*/);
void master_sync_rule_cb(struct evhttp_request *req, void *arg) {
  struct evhttp_connection *conn = arg;
  char *address;
  uint16_t port;
  int code;
  evhttp_connection_get_peer(conn, &address, &port);
  if (!req) {
    t01_log(3, "Failed to connect to slave %s:%d", address, port);
    evhttp_connection_free(conn);
    mark_slave_offline(address, port);
    return;
  }
  code = evhttp_request_get_response_code(req);
  if (code == 200) {
    t01_log(3, "Succeed to sync rule with slave %s:%d", address, port);
  } else {
    if (code == 0)
      mark_slave_offline(address, port);
    t01_log(3, "Failed to sync rule with slave %s:%d", address, port);
  }
}


x86 assembly (clang, -O0):
<master_sync_rule_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <evhttp_connection_get_peer@plt>
cmpq   $0x0,-0x8(%rbp)
jne    11b6 <master_sync_rule_cb+0x66>
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x3,%edi
lea    0xe69(%rip),%rsi
call   1040 <t01_log@plt>
mov    -0x18(%rbp),%rdi
call   1030 <evhttp_connection_free@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <mark_slave_offline@plt>
jmp    121a <master_sync_rule_cb+0xca>
mov    -0x8(%rbp),%rdi
call   1070 <evhttp_request_get_response_code@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xc8,-0x28(%rbp)
jne    11ec <master_sync_rule_cb+0x9c>
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x3,%edi
lea    0xe3f(%rip),%rsi
call   1040 <t01_log@plt>
jmp    121a <master_sync_rule_cb+0xca>
cmpl   $0x0,-0x28(%rbp)
jne    1202 <master_sync_rule_cb+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <mark_slave_offline@plt>
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x3,%edi
lea    0xe32(%rip),%rsi
call   1040 <t01_log@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<master_sync_rule_cb>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1050 <evhttp_connection_get_peer@plt>
test   %rbx,%rbx
je     1199 <master_sync_rule_cb+0x49>
mov    %rbx,%rdi
call   1070 <evhttp_request_get_response_code@plt>
test   %eax,%eax
je     11cb <master_sync_rule_cb+0x7b>
cmp    $0xc8,%eax
jne    11d9 <master_sync_rule_cb+0x89>
mov    0x10(%rsp),%rdx
mov    0xc(%rsp),%ecx
lea    0xe8a(%rip),%rsi
jmp    11e9 <master_sync_rule_cb+0x99>
mov    0x10(%rsp),%rdx
mov    0xc(%rsp),%ecx
lea    0xe57(%rip),%rsi
mov    $0x3,%edi
call   1040 <t01_log@plt>
mov    %r14,%rdi
call   1030 <evhttp_connection_free@plt>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1060 <mark_slave_offline@plt>
jmp    11f3 <master_sync_rule_cb+0xa3>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1060 <mark_slave_offline@plt>
mov    0x10(%rsp),%rdx
mov    0xc(%rsp),%ecx
lea    0xe5e(%rip),%rsi
mov    $0x3,%edi
call   1040 <t01_log@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.evhttp_request = type { i32 }
%struct.evhttp_connection = type { i32 }
@.str = [33 x i8] c"Failed to connect to slave %s:%d\00"
@.str.1 = [38 x i8] c"Succeed to sync rule with slave %s:%d\00"
@.str.2 = [37 x i8] c"Failed to sync rule with slave %s:%d\00"
define void @master_sync_rule_cb(%struct.evhttp_request* %0, i8* %1) {
%3 = alloca %struct.evhttp_request*
%4 = alloca i8*
%5 = alloca %struct.evhttp_connection*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.evhttp_request* %0, %struct.evhttp_request** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = bitcast i8* %9 to %struct.evhttp_connection*
store %struct.evhttp_connection* %10, %struct.evhttp_connection** %5
%11 = load %struct.evhttp_connection*, %struct.evhttp_connection** %5
%12 = call i32 @evhttp_connection_get_peer(%struct.evhttp_connection* %11, i8** %6, i32* %7)
%13 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%14 = icmp ne %struct.evhttp_request* %13, null
br i1 %14, label %24, label %15
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
%19 = load %struct.evhttp_connection*, %struct.evhttp_connection** %5
%20 = call i32 @evhttp_connection_free(%struct.evhttp_connection* %19)
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i32 @mark_slave_offline(i8* %21, i32 %22)
br label %44
24: ; preds = %2
%25 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%26 = call i32 @evhttp_request_get_response_code(%struct.evhttp_request* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 200
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
br label %44
33: ; preds = %24
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i8*, i8** %6
%38 = load i32, i32* %7
%39 = call i32 @mark_slave_offline(i8* %37, i32 %38)
br label %40
40: ; preds = %36, %33
%41 = load i8*, i8** %6
%42 = load i32, i32* %7
%43 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42)
br label %44
44: ; preds = %15, %40, %29
ret void
}

LLVM IR (-O2):
%struct.evhttp_request = type { i32 }
%struct.evhttp_connection = type { i32 }
@.str = [33 x i8] c"Failed to connect to slave %s:%d\00"
@.str.1 = [38 x i8] c"Succeed to sync rule with slave %s:%d\00"
@.str.2 = [37 x i8] c"Failed to sync rule with slave %s:%d\00"
define void @master_sync_rule_cb(%struct.evhttp_request* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8* %1 to %struct.evhttp_connection*
%6 = bitcast i8** %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = call i32 @evhttp_connection_get_peer(%struct.evhttp_connection* %5, i8** %3, i32* %4)
%9 = icmp eq %struct.evhttp_request* %0, null
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
%14 = call i32 @evhttp_connection_free(%struct.evhttp_connection* %5)
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = call i32 @mark_slave_offline(i8* %15, i32 %16)
br label %32
18: ; preds = %2
%19 = call i32 @evhttp_request_get_response_code(%struct.evhttp_request* %0)
switch i32 %19, label %28 [
i32 200, label %20
i32 0, label %24
]
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22)
br label %32
24: ; preds = %18
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = call i32 @mark_slave_offline(i8* %25, i32 %26)
br label %28
28: ; preds = %18, %24
%29 = load i8*, i8** %3
%30 = load i32, i32* %4
%31 = call i32 @t01_log(i32 3, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %20, %28, %10
ret void
}