#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;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ *strchr(char *, char);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *const, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
size_t write(int const, char *, size_t);
size_t irc_putline(int const fd, char const *const line) {
  char ctime[20];
  char linecpy[510 + 1];
  size_t i, len, ret;
  time_t stime;
  if (line == NULL) {
    return (0);
  }
  strncpy(linecpy, line, 510 + 1);
  for (i = 0; i < strlen(linecpy); ++i) {
    if (strchr("\r\n", linecpy[i]) != NULL) {
      linecpy[i] = '\000';
      break;
    }
  }
  if (strlen(linecpy) < 510) {
    len = strlen(linecpy);
  } else {
    len = 510;
  }
  ret = write(fd, linecpy, len);
  ret += write(fd, "\r\n", strlen("\r\n"));
  if (line[0] != '\000') {
    stime = time(NULL);
    strftime(ctime, 20, "%Y/%m/%d %H:%M:%S", localtime(&stime));
    fputs(ctime, stdout);
    fputs(" < ", stdout);
    puts(linecpy);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<irc_putline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <irc_putline+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    137a <irc_putline+0x1ea>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1ff,%edx
call   1040 <strncpy@plt>
movq   $0x0,-0x238(%rbp)
mov    -0x238(%rbp),%rax
mov    %rax,-0x258(%rbp)
lea    -0x230(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rcx
mov    -0x258(%rbp),%rax
cmp    %rcx,%rax
jae    125c <irc_putline+0xcc>
mov    -0x238(%rbp),%rax
lea    0xdeb(%rip),%rdi
movsbl -0x230(%rbp,%rax,1),%esi
ff
call   1080 <strchr@plt>
cmp    $0x0,%rax
je     1240 <irc_putline+0xb0>
mov    -0x238(%rbp),%rax
movb   $0x0,-0x230(%rbp,%rax,1)
jmp    125c <irc_putline+0xcc>
jmp    1245 <irc_putline+0xb5>
mov    -0x238(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x238(%rbp)
jmp    11da <irc_putline+0x4a>
lea    -0x230(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1fe,%rax
jae    128c <irc_putline+0xfc>
lea    -0x230(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x240(%rbp)
jmp    1297 <irc_putline+0x107>
movq   $0x1fe,-0x240(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x240(%rbp),%rdx
call   1060 <write@plt>
mov    %rax,-0x248(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x25c(%rbp)
lea    0xd3c(%rip),%rdi
call   1070 <strlen@plt>
mov    -0x25c(%rbp),%edi
mov    %rax,%rdx
lea    0xd27(%rip),%rsi
call   1060 <write@plt>
add    -0x248(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     136f <irc_putline+0x1df>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <time@plt>
mov    %eax,-0x24c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x268(%rbp)
lea    -0x24c(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x268(%rbp),%rdi
mov    %eax,%ecx
mov    $0x14,%esi
lea    0xccc(%rip),%rdx
call   10b0 <strftime@plt>
lea    -0x30(%rbp),%rdi
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
call   1090 <fputs@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
lea    0xcb7(%rip),%rdi
call   1090 <fputs@plt>
lea    -0x230(%rbp),%rdi
call   1050 <puts@plt>
mov    -0x248(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_putline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x230,%rsp
test   %rsi,%rsi
je     11d9 <irc_putline+0x49>
mov    %rsi,%r12
mov    %edi,%r14d
lea    0x30(%rsp),%rdi
mov    $0x1ff,%edx
call   1040 <strncpy@plt>
mov    0x30(%rsp),%al
test   %al,%al
je     122c <irc_putline+0x9c>
movsbl %al,%esi
lea    0xe35(%rip),%rdi
call   1080 <strchr@plt>
test   %rax,%rax
je     11e0 <irc_putline+0x50>
xor    %ebx,%ebx
jmp    1227 <irc_putline+0x97>
xor    %ebp,%ebp
jmp    12d0 <irc_putline+0x140>
mov    $0x1,%ebx
lea    0x30(%rsp),%rbp
lea    0xe0f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <strlen@plt>
cmp    %rax,%rbx
jae    122c <irc_putline+0x9c>
movsbl 0x30(%rsp,%rbx,1),%esi
mov    %r15,%rdi
call   1080 <strchr@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1200 <irc_putline+0x70>
add    $0xffffffffffffffff,%rbx
movb   $0x0,0x30(%rsp,%rbx,1)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
cmp    $0x1fe,%rax
mov    $0x1fe,%edx
cmovb  %rax,%rdx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1060 <write@plt>
mov    %rax,%rbx
lea    0xda3(%rip),%rsi
mov    $0x2,%edx
mov    %r14d,%edi
call   1060 <write@plt>
mov    %rax,%rbp
add    %rbx,%rbp
cmpb   $0x0,(%r12)
je     12d0 <irc_putline+0x140>
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xd70(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x14,%esi
mov    %eax,%ecx
call   10b0 <strftime@plt>
mov    0x2d32(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <fputs@plt>
mov    (%rbx),%esi
lea    0xd54(%rip),%rdi
call   1090 <fputs@plt>
lea    0x30(%rsp),%rdi
call   1050 <puts@plt>
mov    %rbp,%rax
add    $0x230,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [18 x i8] c"%Y/%m/%d %H:%M:%S\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c" < \00"
define i64 @irc_putline(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca [511 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i64 0, i64* %3
br label %74
15: ; preds = %2
%16 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @strncpy(i8* %16, i8* %17, i32 511)
store i64 0, i64* %8
br label %19
19: ; preds = %34, %15
%20 = load i64, i64* %8
%21 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = load i64, i64* %8
%26 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i32* @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %27)
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i64, i64* %8
%32 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 %31
store i8 0, i8* %32
br label %37
33: ; preds = %24
br label %34
34: ; preds = %33
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
br label %19
37: ; preds = %30, %19
%38 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = icmp ult i64 %39, 510
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
store i64 %43, i64* %9
br label %45
44: ; preds = %37
store i64 510, i64* %9
br label %45
45: ; preds = %44, %41
%46 = load i32, i32* %4
%47 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%48 = load i64, i64* %9
%49 = call i64 @write(i32 %46, i8* %47, i64 %48)
store i64 %49, i64* %10
%50 = load i32, i32* %4
%51 = call i64 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%52 = call i64 @write(i32 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 %51)
%53 = load i64, i64* %10
%54 = add i64 %53, %52
store i64 %54, i64* %10
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 0
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %72
60: ; preds = %45
%61 = call i32 @time(i32* null)
store i32 %61, i32* %11
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%63 = call i32 @localtime(i32* %11)
%64 = call i32 @strftime(i8* %62, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%66 = load i32, i32* @stdout
%67 = call i32 @fputs(i8* %65, i32 %66)
%68 = load i32, i32* @stdout
%69 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds [511 x i8], [511 x i8]* %7, i64 0, i64 0
%71 = call i32 @puts(i8* %70)
br label %72
72: ; preds = %60, %45
%73 = load i64, i64* %10
store i64 %73, i64* %3
br label %74
74: ; preds = %72, %14
%75 = load i64, i64* %3
ret i64 %75
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [18 x i8] c"%Y/%m/%d %H:%M:%S\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c" < \00"
define i64 @irc_putline(i32 %0, i8* %1) {
%3 = alloca [20 x i8]
%4 = alloca [511 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [511 x i8], [511 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i8* %1, null
br i1 %9, label %48, label %10
10: ; preds = %2
%11 = call i32 @strncpy(i8* %7, i8* %1, i32 511)
%12 = load i8, i8* %7
%13 = icmp eq i8 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %10
%15 = call i32* @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %25, %14
%18 = phi i64 [ 0, %14 ], [ %22, %25 ]
%19 = getelementptr inbounds [511 x i8], [511 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
br label %30
20: ; preds = %14, %25
%21 = phi i64 [ %22, %25 ], [ 0, %14 ]
%22 = add nuw i64 %21, 1
%23 = call i64 @strlen(i8* %7)
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = getelementptr inbounds [511 x i8], [511 x i8]* %4, i64 0, i64 %22
%27 = load i8, i8* %26
%28 = call i32* @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %20, label %17
30: ; preds = %20, %10, %17
%31 = call i64 @strlen(i8* %7)
%32 = icmp ult i64 %31, 510
%33 = select i1 %32, i64 %31, i64 510
%34 = call i64 @write(i32 %0, i8* %7, i64 %33)
%35 = call i64 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2)
%36 = add i64 %35, %34
%37 = load i8, i8* %1
%38 = icmp eq i8 %37, 0
br i1 %38, label %48, label %39
39: ; preds = %30
%40 = call i32 @time(i32* null)
store i32 %40, i32* %5
%41 = call i32 @localtime(i32* %5)
%42 = call i32 @strftime(i8* %6, i32 20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @stdout
%44 = call i32 @fputs(i8* %6, i32 %43)
%45 = load i32, i32* @stdout
%46 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = call i32 @puts(i8* %7)
br label %48
48: ; preds = %30, %39, %2
%49 = phi i64 [ 0, %2 ], [ %36, %39 ], [ %36, %30 ]
ret i64 %49
}