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

/* Variables and functions */
int /*<<< orphan*/ *appaserver_error_open_append_file(char *);
int /*<<< orphan*/ date_get_utc_offset();
char *date_now_hhmmss(int /*<<< orphan*/);
char *date_now_yyyy_mm_dd(int /*<<< orphan*/);
char *environ_get_environment(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void appaserver_error_starting_argv_append_file(int argc, char **argv,
                                                char *application_name) {
  FILE *f;
  char *remote_ip_address;
  f = appaserver_error_open_append_file(application_name);
  remote_ip_address = environ_get_environment("REMOTE_ADDR");
  if (remote_ip_address && *remote_ip_address) {
    fprintf(f, "%s %s %s: %s", remote_ip_address,
            date_now_yyyy_mm_dd(date_get_utc_offset()),
            date_now_hhmmss(date_get_utc_offset()), argv[0]);
  } else {
    fprintf(f, "%s %s: %s", date_now_yyyy_mm_dd(date_get_utc_offset()),
            date_now_hhmmss(date_get_utc_offset()), argv[0]);
  }
  while (--argc)
    fprintf(f, " %s", *++argv);
  fprintf(f, "\n");
  fclose(f);
}


x86 assembly (clang, -O0):
<appaserver_error_starting_argv_append_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <appaserver_error_open_append_file@plt>
mov    %rax,-0x20(%rbp)
lea    0xe69(%rip),%rdi
call   1070 <environ_get_environment@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1214 <appaserver_error_starting_argv_append_file+0xa4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1214 <appaserver_error_starting_argv_append_file+0xa4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1030 <date_now_yyyy_mm_dd@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1060 <date_now_hhmmss@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %rax,%r8
mov    -0x10(%rbp),%rax
mov    (%rax),%r9
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    125c <appaserver_error_starting_argv_append_file+0xec>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1030 <date_now_yyyy_mm_dd@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1060 <date_now_hhmmss@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1261 <appaserver_error_starting_argv_append_file+0xf1>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     129d <appaserver_error_starting_argv_append_file+0x12d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1261 <appaserver_error_starting_argv_append_file+0xf1>
mov    -0x20(%rbp),%rdi
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appaserver_error_starting_argv_append_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rdx,%rdi
call   10a0 <appaserver_error_open_append_file@plt>
mov    %rax,%r13
lea    0xe5d(%rip),%rdi
call   1080 <environ_get_environment@plt>
test   %rax,%rax
je     11f9 <appaserver_error_starting_argv_append_file+0x79>
mov    %rax,%rbp
cmpb   $0x0,(%rax)
je     11f9 <appaserver_error_starting_argv_append_file+0x79>
xor    %eax,%eax
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1030 <date_now_yyyy_mm_dd@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1070 <date_now_hhmmss@plt>
mov    (%r14),%r9
lea    0xe2e(%rip),%rsi
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %r12,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
cmp    $0x1,%r15d
jne    1238 <appaserver_error_starting_argv_append_file+0xb8>
jmp    1269 <appaserver_error_starting_argv_append_file+0xe9>
xor    %eax,%eax
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1030 <date_now_yyyy_mm_dd@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <date_get_utc_offset@plt>
mov    %eax,%edi
call   1070 <date_now_hhmmss@plt>
mov    (%r14),%r8
lea    0xded(%rip),%rsi
mov    %r13,%rdi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
cmp    $0x1,%r15d
je     1269 <appaserver_error_starting_argv_append_file+0xe9>
mov    %r15d,%ebx
mov    $0x1,%ebp
lea    0xdce(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rdx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1250 <appaserver_error_starting_argv_append_file+0xd0>
mov    $0xa,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"REMOTE_ADDR\00"
@.str.1 = [13 x i8] c"%s %s %s: %s\00"
@.str.2 = [10 x i8] c"%s %s: %s\00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @appaserver_error_starting_argv_append_file(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32* @appaserver_error_open_append_file(i8* %9)
store i32* %10, i32** %7
%11 = call i8* @environ_get_environment(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %30
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i32*, i32** %7
%21 = load i8*, i8** %8
%22 = call i32 (...) @date_get_utc_offset()
%23 = call i8* @date_now_yyyy_mm_dd(i32 %22)
%24 = call i32 (...) @date_get_utc_offset()
%25 = call i8* @date_now_hhmmss(i32 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23, i8* %25, i8* %28)
br label %40
30: ; preds = %14, %3
%31 = load i32*, i32** %7
%32 = call i32 (...) @date_get_utc_offset()
%33 = call i8* @date_now_yyyy_mm_dd(i32 %32)
%34 = call i32 (...) @date_get_utc_offset()
%35 = call i8* @date_now_hhmmss(i32 %34)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %35, i8* %38)
br label %40
40: ; preds = %30, %19
br label %41
41: ; preds = %45, %40
%42 = load i32, i32* %4
%43 = add nsw i32 %42, -1
store i32 %43, i32* %4
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i32*, i32** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i32 1
store i8** %48, i8*** %5
%49 = load i8*, i8** %48
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %49)
br label %41
51: ; preds = %41
%52 = load i32*, i32** %7
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32*, i32** %7
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"REMOTE_ADDR\00"
@.str.1 = [13 x i8] c"%s %s %s: %s\00"
@.str.2 = [10 x i8] c"%s %s: %s\00"
@.str.3 = [4 x i8] c" %s\00"
define void @appaserver_error_starting_argv_append_file(i32 %0, i8** nocapture %1, i8* %2) {
%4 = tail call i32* @appaserver_error_open_append_file(i8* %2)
%5 = tail call i8* @environ_get_environment(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i32 (...) @date_get_utc_offset()
%12 = tail call i8* @date_now_yyyy_mm_dd(i32 %11)
%13 = tail call i32 (...) @date_get_utc_offset()
%14 = tail call i8* @date_now_hhmmss(i32 %13)
%15 = load i8*, i8** %1
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %12, i8* %14, i8* %15)
br label %24
17: ; preds = %7, %3
%18 = tail call i32 (...) @date_get_utc_offset()
%19 = tail call i8* @date_now_yyyy_mm_dd(i32 %18)
%20 = tail call i32 (...) @date_get_utc_offset()
%21 = tail call i8* @date_now_hhmmss(i32 %20)
%22 = load i8*, i8** %1
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %21, i8* %22)
br label %24
24: ; preds = %17, %10
%25 = add nsw i32 %0, -1
%26 = icmp eq i32 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %24, %27
%28 = phi i32 [ %33, %27 ], [ %25, %24 ]
%29 = phi i8** [ %30, %27 ], [ %1, %24 ]
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = add nsw i32 %28, -1
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %27
35: ; preds = %27, %24
%36 = tail call i32 @fputc(i32 10, i32* %4)
%37 = tail call i32 @fclose(i32* %4)
ret void
}