#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 time_t;
typedef int /*<<< orphan*/ fnbuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ gmtime(int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
FILE *output_for_hour(char *prefix, int hournum, int period) {
  static char fnbuf[4096];
  FILE *outfp = NULL;
  time_t stamp = hournum * period;
  strncpy(fnbuf, prefix, sizeof(fnbuf));
  strftime(fnbuf + strlen(prefix), sizeof(fnbuf) - strlen(prefix) - 1,
           "%Y-%m-%d-%H-%M.ipfix", gmtime(&stamp));
  if (!(outfp = fopen(fnbuf, "wb"))) {
    fprintf(stderr, "could not open output file %s: %s", fnbuf,
            strerror(errno));
    exit(1);
  }
  return outfp;
}


x86 assembly (clang, -O0):
<output_for_hour>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2ec1(%rip),%rdi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    0x2ea4(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    $0x1000,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x20(%rbp)
lea    -0x1c(%rbp),%rdi
call   1080 <gmtime@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    %eax,%ecx
lea    0xdf9(%rip),%rdx
call   1060 <strftime@plt>
lea    0x2e5d(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    126a <output_for_hour+0xea>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rcx
lea    0xdc4(%rip),%rsi
lea    0x2e15(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_for_hour>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
imul   %edx,%esi
mov    %esi,0x4(%rsp)
lea    0x2ed8(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    $0xfff,%ebp
sub    %eax,%ebp
lea    0x4(%rsp),%rdi
call   1080 <gmtime@plt>
lea    0xe2a(%rip),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%ecx
call   1060 <strftime@plt>
lea    0xe2c(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1201 <output_for_hour+0x81>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdf9(%rip),%rsi
lea    0x2e4a(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@output_for_hour.fnbuf = internal global [4096 x i8] zeroinitializer
@.str = [21 x i8] c"%Y-%m-%d-%H-%M.ipfix\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"could not open output file %s: %s\00"
@errno = global i32 0
define i32* @output_for_hour(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32* null, i32** %7
%9 = load i32, i32* %5
%10 = load i32, i32* %6
%11 = mul nsw i32 %9, %10
store i32 %11, i32* %8
%12 = load i8*, i8** %4
%13 = call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* %12, i32 4096)
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i64 %16
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = sub i64 4096, %20
%22 = sub i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i32 @gmtime(i32* %8)
%25 = call i32 @strftime(i8* %17, i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32* @fopen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %7
%27 = icmp ne i32* %26, null
br i1 %27, label %34, label %28
28: ; preds = %3
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %3
%35 = load i32*, i32** %7
ret i32* %35
}

LLVM IR (-O2):
@output_for_hour.fnbuf = internal global [4096 x i8] zeroinitializer
@.str = [21 x i8] c"%Y-%m-%d-%H-%M.ipfix\00"
@.str.1 = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"could not open output file %s: %s\00"
@errno = global i32 0
define noalias i32* @output_for_hour(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = mul nsw i32 %2, %1
store i32 %6, i32* %4
%7 = tail call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* %0, i32 4096)
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 %9
%11 = tail call i32 @strlen(i8* %0)
%12 = sub i32 4095, %11
%13 = call i32 @gmtime(i32* %4)
%14 = call i32 @strftime(i8* %10, i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32* @fopen(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @output_for_hour.fnbuf, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %3
ret i32* %15
}