#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*/ timestr;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
struct tm *localtime(int /*<<< orphan*/ const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int handle_data(char *buf, const int bufsize, const time_t polltime,
                char *datadir) {
  struct tm *loctime;
  char timestr[100];
  char fname[100];
  FILE *logfile;
  loctime = localtime(&polltime);
  strftime(timestr, sizeof(timestr), "%F", loctime);
  sprintf(fname, "%s/%s.%s", datadir, timestr, "txt");
  if ((logfile = fopen(fname, "a")) == NULL) {
    perror("Client: fopen()");
    return -1;
  }
  strftime(timestr, sizeof(timestr), "%F %T", loctime);
  printf("Client: %s;%s\n", timestr, buf);
  fprintf(logfile, "%s;%s\n", timestr, buf);
  fclose(logfile);
  return 0;
}


x86 assembly (clang, -O0):
<handle_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x64,%esi
lea    0xe43(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x100(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    -0x90(%rbp),%rcx
lea    0xe28(%rip),%rsi
lea    0xe2a(%rip),%r8
call   10a0 <sprintf@plt>
lea    -0x100(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x108(%rbp)
cmp    $0x0,%rax
jne    1223 <handle_data+0xa3>
lea    0xe00(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1287 <handle_data+0x107>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x64,%esi
lea    0xde8(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x90(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
mov    -0x108(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x108(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf0,%rsp
mov    %rcx,%r13
mov    %rdi,%r14
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%r15
lea    0xe52(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x64,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
lea    0xe39(%rip),%rsi
lea    0xe3b(%rip),%r8
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
call   10a0 <sprintf@plt>
lea    0xe22(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     125c <handle_data+0xdc>
mov    %rax,%rbx
lea    0xe1d(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x64,%esi
mov    %r15,%rcx
call   1070 <strftime@plt>
lea    0xe07(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r14,%rcx
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdaf(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
jmp    124b <handle_data+0xcb>

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%F\00"
@.str.1 = [9 x i8] c"%s/%s.%s\00"
@.str.2 = [4 x i8] c"txt\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [16 x i8] c"Client: fopen()\00"
@.str.5 = [6 x i8] c"%F %T\00"
@.str.6 = [15 x i8] c"Client: %s;%s\0A\00"
@.str.7 = [7 x i8] c"%s;%s\0A\00"
define i32 @handle_data(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.tm*
%11 = alloca [100 x i8]
%12 = alloca [100 x i8]
%13 = alloca i32*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%14 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %14, %struct.tm** %10
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%16 = load %struct.tm*, %struct.tm** %10
%17 = call i32 @strftime(i8* %15, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%19 = load i8*, i8** %9
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %13
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %40
27: ; preds = %4
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%29 = load %struct.tm*, %struct.tm** %10
%30 = call i32 @strftime(i8* %28, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %29)
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%32 = load i8*, i8** %6
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %31, i8* %32)
%34 = load i32*, i32** %13
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i32*, i32** %13
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %5
br label %40
40: ; preds = %27, %25
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [3 x i8] c"%F\00"
@.str.1 = [9 x i8] c"%s/%s.%s\00"
@.str.2 = [4 x i8] c"txt\00"
@.str.3 = [2 x i8] c"a\00"
@.str.4 = [16 x i8] c"Client: fopen()\00"
@.str.5 = [6 x i8] c"%F %T\00"
@.str.6 = [15 x i8] c"Client: %s;%s\0A\00"
@.str.7 = [7 x i8] c"%s;%s\0A\00"
define i32 @handle_data(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
store i32 %2, i32* %5
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%10 = call %struct.tm* @localtime(i32* %5)
%11 = call i32 @strftime(i8* %8, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %22
17: ; preds = %4
%18 = call i32 @strftime(i8* %8, i32 100, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %struct.tm* %10)
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %8, i8* %0)
%20 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %0)
%21 = call i32 @fclose(i32* %13)
br label %22
22: ; preds = %17, %15
%23 = phi i32 [ -1, %15 ], [ 0, %17 ]
ret i32 %23
}