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

/* Variables and functions */
char *asctime(struct tm *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t const, size_t);
struct tm *localtime(int /*<<< orphan*/ *);
size_t rio_writen(int, char *, size_t const);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ stderr;
char *strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void func(int fd, const char *buf) {
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  char content[8192 + 1];
  snprintf(content, 8192, "Welcome to time.com: ");
  snprintf(content, 8192, "%sTHE Internet time portal.\r\n<p>", content);
  snprintf(content, 8192, "%sCurrent time is: %s\r\n<p>", content,
           asctime(timeinfo));
  snprintf(content, 8192, "%sThanks for visiting!\r\n", content);
  char result[8192 + 1];
  snprintf(result, 8192,
           "Content-length: %ld\r\nContent-type: text/html\r\n\r\n%s",
           strlen(content), content);
  const size_t length = strlen(result);
  size_t written;
  if (length != (written = rio_writen(fd, result, length))) {
    fprintf(stderr, "expect to write %ld, written %ld\n", length, written);
  }
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4070,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1090 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
lea    -0x2030(%rbp),%rdi
mov    $0x2000,%esi
lea    0xe55(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x2030(%rbp),%rdi
lea    -0x2030(%rbp),%rcx
mov    $0x2000,%esi
lea    0xe4a(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x2030(%rbp),%rax
mov    %rax,-0x4070(%rbp)
lea    -0x2030(%rbp),%rax
mov    %rax,-0x4068(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <asctime@plt>
mov    -0x4070(%rbp),%rdi
mov    -0x4068(%rbp),%rcx
mov    %rax,%r8
mov    $0x2000,%esi
lea    0xe22(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x2030(%rbp),%rdi
lea    -0x2030(%rbp),%rcx
mov    $0x2000,%esi
lea    0xe1c(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x4040(%rbp),%rax
mov    %rax,-0x4060(%rbp)
lea    -0x2030(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4060(%rbp),%rdi
mov    %rax,%rcx
lea    -0x2030(%rbp),%r8
mov    $0x2000,%esi
lea    0xdf7(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x4040(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x4048(%rbp)
mov    -0x4048(%rbp),%rax
mov    %rax,-0x4058(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x4040(%rbp),%rsi
mov    -0x4048(%rbp),%rdx
call   1080 <rio_writen@plt>
mov    %rax,%rcx
mov    -0x4058(%rbp),%rax
mov    %rcx,-0x4050(%rbp)
cmp    %rcx,%rax
je     12ef <func+0x17f>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
mov    -0x4048(%rbp),%rdx
mov    -0x4050(%rbp),%rcx
lea    0xdb4(%rip),%rsi
call   1070 <fprintf@plt>
add    $0x4070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %rbp
push   %r14
push   %rbx
sub    $0x4030,%rsp
mov    %edi,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rbp
lea    0xe63(%rip),%rdx
lea    0x2020(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2000,%esi
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0xe5b(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2000,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1050 <asctime@plt>
lea    0xe5b(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2000,%esi
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0xe5a(%rip),%rdx
mov    %rbx,%rdi
mov    $0x2000,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe52(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x2000,%esi
mov    %rax,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1080 <rio_writen@plt>
cmp    %rbx,%rax
je     126c <func+0xfc>
mov    0x2d88(%rip),%rcx
mov    (%rcx),%edi
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
add    $0x4030,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [22 x i8] c"Welcome to time.com: \00"
@.str.1 = [33 x i8] c"%sTHE Internet time portal.\0D\0A<p>\00"
@.str.2 = [27 x i8] c"%sCurrent time is: %s\0D\0A<p>\00"
@.str.3 = [25 x i8] c"%sThanks for visiting!\0D\0A\00"
@.str.4 = [51 x i8] c"Content-length: %ld\0D\0AContent-type: text/html\0D\0A\0D\0A%s\00"
@stderr = global i32 0
@.str.5 = [34 x i8] c"expect to write %ld, written %ld\0A\00"
define void @func(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.tm*
%7 = alloca [8193 x i8]
%8 = alloca [8193 x i8]
%9 = alloca i64
%10 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%11 = call i32 @time(i32* %5)
%12 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %12, %struct.tm** %6
%13 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 8192, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %15, i32 8192, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%19 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%20 = load %struct.tm*, %struct.tm** %6
%21 = call i8* @asctime(%struct.tm* %20)
%22 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 8192, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %21)
%23 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %23, i32 8192, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [8193 x i8], [8193 x i8]* %8, i64 0, i64 0
%27 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%28 = call i8* @strlen(i8* %27)
%29 = getelementptr inbounds [8193 x i8], [8193 x i8]* %7, i64 0, i64 0
%30 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %26, i32 8192, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %28, i8* %29)
%31 = getelementptr inbounds [8193 x i8], [8193 x i8]* %8, i64 0, i64 0
%32 = call i8* @strlen(i8* %31)
%33 = ptrtoint i8* %32 to i64
store i64 %33, i64* %9
%34 = load i64, i64* %9
%35 = load i32, i32* %3
%36 = getelementptr inbounds [8193 x i8], [8193 x i8]* %8, i64 0, i64 0
%37 = load i64, i64* %9
%38 = call i64 @rio_writen(i32 %35, i8* %36, i64 %37)
store i64 %38, i64* %10
%39 = icmp ne i64 %34, %38
br i1 %39, label %40, label %45
40: ; preds = %2
%41 = load i32, i32* @stderr
%42 = load i64, i64* %9
%43 = load i64, i64* %10
%44 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %42, i64 %43)
br label %45
45: ; preds = %40, %2
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [22 x i8] c"Welcome to time.com: \00"
@.str.1 = [33 x i8] c"%sTHE Internet time portal.\0D\0A<p>\00"
@.str.2 = [27 x i8] c"%sCurrent time is: %s\0D\0A<p>\00"
@.str.3 = [25 x i8] c"%sThanks for visiting!\0D\0A\00"
@.str.4 = [51 x i8] c"Content-length: %ld\0D\0AContent-type: text/html\0D\0A\0D\0A%s\00"
@stderr = global i32 0
@.str.5 = [34 x i8] c"expect to write %ld, written %ld\0A\00"
define void @func(i32 %0, i8* nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [8193 x i8]
%5 = alloca [8193 x i8]
%6 = bitcast i32* %3 to i8*
%7 = call i32 @time(i32* %3)
%8 = call %struct.tm* @localtime(i32* %3)
%9 = getelementptr inbounds [8193 x i8], [8193 x i8]* %4, i64 0, i64 0
%10 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 8192, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 8192, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = call i8* @asctime(%struct.tm* %8)
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 8192, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %12)
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %9, i32 8192, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%15 = getelementptr inbounds [8193 x i8], [8193 x i8]* %5, i64 0, i64 0
%16 = call i8* @strlen(i8* %9)
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %15, i32 8192, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %16, i8* %9)
%18 = call i8* @strlen(i8* %15)
%19 = ptrtoint i8* %18 to i64
%20 = call i64 @rio_writen(i32 %0, i8* %15, i64 %19)
%21 = icmp eq i64 %20, %19
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i64 %19, i64 %20)
br label %25
25: ; preds = %22, %2
ret void
}