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

/* Variables and functions */
int /*<<< orphan*/ evhttp_connection_get_peer(struct evhttp_connection *,
                                              char **, unsigned short *);
struct evhttp_connection *
evhttp_request_get_connection(struct evhttp_request *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void log_client_IP(struct evhttp_request *req, FILE *fh) {
  char *ip;
  unsigned short port;
  struct evhttp_connection *evcon;
  evcon = evhttp_request_get_connection(req);
  if (evcon) {
    evhttp_connection_get_peer(evcon, &ip, &port);
    fprintf(fh, "%s", ip);
    fflush(fh);
  } else {
    fprintf(fh, "evhttp_connection_get_peer() "
                "fails.\n");
  }
}


x86 assembly (clang, -O0):
<log_client_IP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <evhttp_request_get_connection@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119d <log_client_IP+0x5d>
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1a(%rbp),%rdx
call   1060 <evhttp_connection_get_peer@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fflush@plt>
jmp    11af <log_client_IP+0x6f>
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_client_IP>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
call   1040 <evhttp_request_get_connection@plt>
test   %rax,%rax
je     118f <log_client_IP+0x3f>
lea    0x8(%rsp),%rsi
lea    0x6(%rsp),%rdx
mov    %rax,%rdi
call   1060 <evhttp_connection_get_peer@plt>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <fputs@plt>
mov    %rbx,%rdi
call   1050 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6a(%rip),%rdi
mov    $0x24,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x10,%rsp
pop    %rbx
jmp    1070 <fwrite@plt>

LLVM IR (-O0):
%struct.evhttp_request = type { i32 }
%struct.evhttp_connection = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [37 x i8] c"evhttp_connection_get_peer() fails.\0A\00"
define void @log_client_IP(%struct.evhttp_request* %0, i32* %1) {
%3 = alloca %struct.evhttp_request*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i16
%7 = alloca %struct.evhttp_connection*
store %struct.evhttp_request* %0, %struct.evhttp_request** %3
store i32* %1, i32** %4
%8 = load %struct.evhttp_request*, %struct.evhttp_request** %3
%9 = call %struct.evhttp_connection* @evhttp_request_get_connection(%struct.evhttp_request* %8)
store %struct.evhttp_connection* %9, %struct.evhttp_connection** %7
%10 = load %struct.evhttp_connection*, %struct.evhttp_connection** %7
%11 = icmp ne %struct.evhttp_connection* %10, null
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load %struct.evhttp_connection*, %struct.evhttp_connection** %7
%14 = call i32 @evhttp_connection_get_peer(%struct.evhttp_connection* %13, i8** %5, i16* %6)
%15 = load i32*, i32** %4
%16 = load i8*, i8** %5
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %4
%19 = call i32 @fflush(i32* %18)
br label %23
20: ; preds = %2
%21 = load i32*, i32** %4
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %12
ret void
}

LLVM IR (-O2):
%struct.evhttp_request = type { i32 }
%struct.evhttp_connection = type { i32 }
@.str.1 = [37 x i8] c"evhttp_connection_get_peer() fails.\0A\00"
define void @log_client_IP(%struct.evhttp_request* %0, i32* nocapture %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = bitcast i8** %3 to i8*
%6 = bitcast i16* %4 to i8*
%7 = tail call %struct.evhttp_connection* @evhttp_request_get_connection(%struct.evhttp_request* %0)
%8 = icmp eq %struct.evhttp_connection* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call i32 @evhttp_connection_get_peer(%struct.evhttp_connection* %7, i8** %3, i16* %4)
%11 = load i8*, i8** %3
%12 = call i32 @fputs(i8* %11, i32* %1)
%13 = call i32 @fflush(i32* %1)
br label %16
14: ; preds = %2
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 36, i64 1, i32* %1)
br label %16
16: ; preds = %14, %9
ret void
}