#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*/ uid_t;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int /*<<< orphan*/ tm_sec;
};
struct passwd {
  char *pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ writelog(char *, char *);
int clog_r(char *rip, char *cmd, int cmdlen) {
  char username[255] = {0};
  uid_t my_uid;
  struct passwd *my_info;
  my_uid = getuid();
  my_info = getpwuid(my_uid);
  if (my_info) {
    strcpy(username, my_info->pw_name);
  } else {
    strcpy(username, "Unkown");
  }
  time_t seconds = time((time_t *)NULL);
  struct tm *t;
  t = localtime(&seconds);
  char strtime[64] = {0};
  sprintf(strtime, "%04d%02d%02d %02d:%02d:%02d", t->tm_year + 1900,
          t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
  char *plog = (char *)malloc(cmdlen + 100);
  memset(plog, 0, cmdlen + 100);
  sprintf(plog, "%s %s IP[%s] CMD:%s\n", strtime, username, rip, cmd);
  char logfile[24] = "cssh.log";
  writelog(logfile, plog);
  free(plog);
  return 0;
}


x86 assembly (clang, -O0):
<clog_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
mov    $0x0,%al
call   1080 <getuid@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%edi
call   1060 <getpwuid@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
je     1211 <clog_r+0x71>
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rax
mov    (%rax),%rsi
call   1050 <strcpy@plt>
jmp    1224 <clog_r+0x84>
lea    -0x120(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1050 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x134(%rbp)
lea    -0x134(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x140(%rbp)
lea    -0x180(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1090 <memset@plt>
lea    -0x180(%rbp),%rdi
mov    -0x140(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x140(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x140(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x140(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x140(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x140(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd59(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x14(%rbp),%edi
add    $0x64,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x188(%rbp)
mov    -0x188(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x64,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x188(%rbp),%rdi
lea    -0x180(%rbp),%rdx
lea    -0x120(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    0xd2b(%rip),%rax
mov    %rax,-0x1a0(%rbp)
mov    0xd25(%rip),%rax
mov    %rax,-0x198(%rbp)
mov    0xd1f(%rip),%rax
mov    %rax,-0x190(%rbp)
lea    -0x1a0(%rbp),%rdi
mov    -0x188(%rbp),%rsi
call   1070 <writelog@plt>
mov    -0x188(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clog_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    %edx,%r14d
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movups %xmm0,0x15f(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
xor    %eax,%eax
call   1080 <getuid@plt>
mov    %eax,%edi
call   1060 <getpwuid@plt>
test   %rax,%rax
je     1254 <clog_r+0xb4>
mov    (%rax),%rsi
jmp    125b <clog_r+0xbb>
lea    0xda5(%rip),%rsi
lea    0x70(%rsp),%r12
mov    %r12,%rdi
call   1050 <strcpy@plt>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <localtime@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
add    $0x1,%ecx
mov    0xc(%rax),%r9d
mov    0x10(%rax),%ebx
mov    0x14(%rax),%ebp
lea    0xd51(%rip),%rsi
lea    0x30(%rsp),%r13
mov    %r13,%rdi
xor    %eax,%eax
push   %rbp
push   %rbx
call   10c0 <sprintf@plt>
add    $0x10,%rsp
add    $0x64,%r14d
mov    %r14d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1090 <memset@plt>
lea    0xd35(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    0x8(%rsp),%r9
xor    %eax,%eax
call   10c0 <sprintf@plt>
movaps 0xd33(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <writelog@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [7 x i8] c"Unkown\00"
@.str.1 = [28 x i8] c"%04d%02d%02d %02d:%02d:%02d\00"
@.str.2 = [21 x i8] c"%s %s IP[%s] CMD:%s\0A\00"
@__const.clog_r.logfile = [24 x i8] c"cssh.log\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @clog_r(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [255 x i8]
%8 = alloca i32
%9 = alloca %struct.passwd*
%10 = alloca i32
%11 = alloca %struct.tm*
%12 = alloca [64 x i8]
%13 = alloca i8*
%14 = alloca [24 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%15 = bitcast [255 x i8]* %7 to i8*
%16 = call i32 (...) @getuid()
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = call %struct.passwd* @getpwuid(i32 %17)
store %struct.passwd* %18, %struct.passwd** %9
%19 = load %struct.passwd*, %struct.passwd** %9
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %21, label %27
21: ; preds = %3
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%23 = load %struct.passwd*, %struct.passwd** %9
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %22, i8* %25)
br label %30
27: ; preds = %3
%28 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %27, %21
%31 = call i32 @time(i32* null)
store i32 %31, i32* %10
%32 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %32, %struct.tm** %11
%33 = bitcast [64 x i8]* %12 to i8*
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%35 = load %struct.tm*, %struct.tm** %11
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1900
%39 = load %struct.tm*, %struct.tm** %11
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1
%43 = load %struct.tm*, %struct.tm** %11
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 2
%45 = load i32, i32* %44
%46 = load %struct.tm*, %struct.tm** %11
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 3
%48 = load i32, i32* %47
%49 = load %struct.tm*, %struct.tm** %11
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 4
%51 = load i32, i32* %50
%52 = load %struct.tm*, %struct.tm** %11
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 5
%54 = load i32, i32* %53
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %42, i32 %45, i32 %48, i32 %51, i32 %54)
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 100
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %13
%60 = load i8*, i8** %13
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 100
%63 = call i32 @memset(i8* %60, i32 0, i32 %62)
%64 = load i8*, i8** %13
%65 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%66 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%67 = load i8*, i8** %4
%68 = load i8*, i8** %5
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %65, i8* %66, i8* %67, i8* %68)
%70 = bitcast [24 x i8]* %14 to i8*
%71 = getelementptr inbounds [24 x i8], [24 x i8]* %14, i64 0, i64 0
%72 = load i8*, i8** %13
%73 = call i32 @writelog(i8* %71, i8* %72)
%74 = load i8*, i8** %13
%75 = call i32 @free(i8* %74)
ret i32 0
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [7 x i8] c"Unkown\00"
@.str.1 = [28 x i8] c"%04d%02d%02d %02d:%02d:%02d\00"
@.str.2 = [21 x i8] c"%s %s IP[%s] CMD:%s\0A\00"
@__const.clog_r.logfile = [24 x i8] c"cssh.log\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @clog_r(i8* %0, i8* %1, i32 %2) {
%4 = alloca [255 x i8]
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca [24 x i8]
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%9 = tail call i32 (...) @getuid()
%10 = tail call %struct.passwd* @getpwuid(i32 %9)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %10, i64 0, i32 0
%14 = load i8*, i8** %13
br label %15
15: ; preds = %3, %12
%16 = phi i8* [ %14, %12 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %3 ]
%17 = call i32 @strcpy(i8* %8, i8* %16)
%18 = bitcast i32* %5 to i8*
%19 = call i32 @time(i32* null)
store i32 %19, i32* %5
%20 = call %struct.tm* @localtime(i32* %5)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 0
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1900
%25 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
%28 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 2
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 3
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %20, i64 0, i32 5
%35 = load i32, i32* %34
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %27, i32 %29, i32 %31, i32 %33, i32 %35)
%37 = add nsw i32 %2, 100
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @memset(i8* %39, i32 0, i32 %37)
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %8, i8* %0, i8* %1)
%42 = getelementptr inbounds [24 x i8], [24 x i8]* %7, i64 0, i64 0
%43 = call i32 @writelog(i8* %42, i8* %39)
%44 = call i32 @free(i8* %39)
ret i32 0
}