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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int cmd_time(char *cmd, int client_fd) {
  time_t t = time(NULL);
  struct tm tm = *localtime(&t);
  char line[30];
  snprintf(line, 30, "now: %04d-%02d-%02d %02d:%02d:%02d\r\n",
           tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
           tm.tm_sec);
  if (send(client_fd, line, strlen(line), 0) == -1)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<cmd_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x2c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x28(%rbp),%r9d
mov    -0x24(%rbp),%r11d
mov    -0x20(%rbp),%r10d
mov    -0x1c(%rbp),%eax
mov    $0x1e,%esi
lea    0xe42(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1060 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
jne    120c <cmd_time+0xbc>
movl   $0x1,-0x4(%rbp)
jmp    1213 <cmd_time+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %esi,%r14d
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%ebx
mov    0x14(%rax),%ebp
mov    $0x76c,%ecx
add    (%rax),%ecx
add    $0x1,%r8d
sub    $0x8,%rsp
lea    0xe66(%rip),%rdx
lea    0x18(%rsp),%r15
mov    %r15,%rdi
mov    $0x1e,%esi
push   %rbp
push   %rbx
push   %r10
call   1060 <snprintf@plt>
add    $0x20,%rsp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
mov    %ecx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [37 x i8] c"now: %04d-%02d-%02d %02d:%02d:%02d\0D\0A\00"
define i32 @cmd_time(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca [30 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i32 @time(i32* null)
store i32 %9, i32* %6
%10 = call %struct.tm* @localtime(i32* %6)
%11 = bitcast %struct.tm* %7 to i8*
%12 = bitcast %struct.tm* %10 to i8*
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
%17 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 5
%27 = load i32, i32* %26
%28 = call i32 @snprintf(i8* %13, i32 30, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27)
%29 = load i32, i32* %5
%30 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @send(i32 %29, i8* %30, i32 %32, i32 0)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %2
store i32 1, i32* %3
br label %37
36: ; preds = %2
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [37 x i8] c"now: %04d-%02d-%02d %02d:%02d:%02d\0D\0A\00"
define i32 @cmd_time(i8* nocapture readnone %0, i32 %1) {
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @localtime(i32* %3)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%19 = load i32, i32* %18
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%21 = add nsw i32 %9, 1900
%22 = add nsw i32 %11, 1
%23 = call i32 @snprintf(i8* %20, i32 30, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, i32 %13, i32 %15, i32 %17, i32 %19)
%24 = call i32 @strlen(i8* %20)
%25 = call i32 @send(i32 %1, i8* %20, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
%27 = zext i1 %26 to i32
ret i32 %27
}