#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 */
struct tm {
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
void rfi_writeheader(FILE *rfifile, const int tracks, const int sides,
                     const long rate, const unsigned char writeable) {
  struct tm tim;
  struct timeval tv;
  if (rfifile == NULL)
    return;
  gettimeofday(&tv, NULL);
  localtime_r(&tv.tv_sec, &tim);
  fprintf(rfifile, "%s", "RFI");
  fprintf(
      rfifile,
      "{date:\"%02d/%02d/"
      "%d\",time:\"%02d:%02d:%02d\",tracks:%d,sides:%d,rate:%ld,writeable:%d}",
      tim.tm_mday, tim.tm_mon + 1, tim.tm_year + 1900, tim.tm_hour, tim.tm_min,
      tim.tm_sec, tracks, sides, rate, writeable);
}


x86 assembly (clang, -O0):
<rfi_writeheader>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %r8b,%al
mov    %rdi,-0x20(%rbp)
mov    %esi,-0x24(%rbp)
mov    %edx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %al,-0x31(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1161 <rfi_writeheader+0x31>
jmp    11f0 <rfi_writeheader+0xc0>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x58(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    0xe76(%rip),%rdx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x48(%rbp),%r8d
add    $0x76c,%r8d
mov    -0x44(%rbp),%r9d
mov    -0x40(%rbp),%r15d
mov    -0x3c(%rbp),%r14d
mov    -0x24(%rbp),%ebx
mov    -0x28(%rbp),%r11d
mov    -0x30(%rbp),%r10
movzbl -0x31(%rbp),%eax
lea    0xe39(%rip),%rsi
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %eax,0x28(%rsp)
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfi_writeheader>:
test   %rdi,%rdi
je     11ee <rfi_writeheader+0xae>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%r13d
mov    %rcx,%r12
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1030 <localtime_r@plt>
lea    0xe77(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
add    $0x1,%ecx
mov    $0x76c,%r8d
add    0x10(%rsp),%r8d
mov    0x14(%rsp),%r9d
mov    0x18(%rsp),%r10d
mov    0x1c(%rsp),%r11d
movzbl %r13b,%ebp
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
push   %rbp
push   %r12
push   %r15
push   %r14
push   %r11
push   %r10
call   1050 <fprintf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"RFI\00"
@.str.2 = [85 x i8] c"{date:\22%02d/%02d/%d\22,time:\22%02d:%02d:%02d\22,tracks:%d,sides:%d,rate:%ld,writeable:%d}\00"
define void @rfi_writeheader(i32* %0, i32 %1, i32 %2, i64 %3, i8 zeroext %4) {
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8
%11 = alloca %struct.tm
%12 = alloca %struct.timeval
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i8 %4, i8* %10
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %5
br label %43
16: ; preds = %5
%17 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%19 = call i32 @localtime_r(i32* %18, %struct.tm* %11)
%20 = load i32*, i32** %6
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32*, i32** %6
%23 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
%28 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 2
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1900
%31 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 3
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 4
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.tm, %struct.tm* %11, i32 0, i32 5
%36 = load i32, i32* %35
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = load i64, i64* %9
%40 = load i8, i8* %10
%41 = zext i8 %40 to i32
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %27, i32 %30, i32 %32, i32 %34, i32 %36, i32 %37, i32 %38, i64 %39, i32 %41)
br label %43
43: ; preds = %16, %15
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.timeval = type { i32 }
@.str.1 = [4 x i8] c"RFI\00"
@.str.2 = [85 x i8] c"{date:\22%02d/%02d/%d\22,time:\22%02d:%02d:%02d\22,tracks:%d,sides:%d,rate:%ld,writeable:%d}\00"
define void @rfi_writeheader(i32* %0, i32 %1, i32 %2, i64 %3, i8 zeroext %4) {
%6 = alloca %struct.tm
%7 = alloca %struct.timeval
%8 = bitcast %struct.tm* %6 to i8*
%9 = bitcast %struct.timeval* %7 to i8*
%10 = icmp eq i32* %0, null
br i1 %10, label %32, label %11
11: ; preds = %5
%12 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%14 = call i32 @localtime_r(i32* %13, %struct.tm* %6)
%15 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 3, i64 1, i32* %0)
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
%21 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1900
%24 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 5
%29 = load i32, i32* %28
%30 = zext i8 %4 to i32
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %20, i32 %23, i32 %25, i32 %27, i32 %29, i32 %1, i32 %2, i64 %3, i32 %30)
br label %32
32: ; preds = %5, %11
ret void
}