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

/* Variables and functions */
int /*<<< orphan*/ _IONBF;
unsigned short co20_get_air_quality();
int /*<<< orphan*/ co20_init();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *,
                           unsigned short);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  unsigned short airValue = 0;
  char date[26];
  time_t timer;
  struct tm *tm_info;
  FILE *csv;
  co20_init();
  csv = fopen("air.csv", "a");
  if (!csv) {
    printf("cannot open air.csv for appending\n");
    return 1;
  }
  setvbuf(csv, NULL, _IONBF, 0);
  while (1) {
    airValue = co20_get_air_quality();
    time(&timer);
    tm_info = localtime(&timer);
    strftime(date, 26, "%d.%m.%Y %H:%M:%S", tm_info);
    fprintf(csv, "%s;%d\n", date, airValue);
    printf("%s;%d\n", date, airValue);
    sleep(2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
mov    $0x0,%al
call   1040 <co20_init@plt>
lea    0xe36(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11fe <main+0x5e>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x48(%rbp),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1080 <setvbuf@plt>
mov    $0x0,%al
call   10b0 <co20_get_air_quality@plt>
mov    %ax,-0x12(%rbp)
lea    -0x34(%rbp),%rdi
call   1070 <time@plt>
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1a,%esi
lea    0xde2(%rip),%rdx
call   1090 <strftime@plt>
mov    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xde0(%rip),%rsi
movzwl -0x12(%rbp),%ecx
call   1060 <fprintf@plt>
lea    -0x30(%rbp),%rsi
movzwl -0x12(%rbp),%edx
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2,%edi
call   10c0 <sleep@plt>
jmp    1216 <main+0x76>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
call   1050 <co20_init@plt>
lea    0xe34(%rip),%rdi
lea    0xe35(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     127a <main+0xca>
mov    %rax,%r14
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
lea    0xc(%rsp),%r12
lea    0xe05(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0xe0b(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10c0 <co20_get_air_quality@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1080 <time@plt>
mov    %r12,%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    $0x1a,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   10a0 <strftime@plt>
movzwl %bp,%ebp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1070 <fprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%edi
call   10d0 <sleep@plt>
jmp    1220 <main+0x70>
lea    0xda2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [8 x i8] c"air.csv\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [35 x i8] c"cannot open air.csv for appending\0A\00"
@_IONBF = global i32 0
@.str.3 = [18 x i8] c"%d.%m.%Y %H:%M:%S\00"
@.str.4 = [7 x i8] c"%s;%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca [26 x i8]
%8 = alloca i32
%9 = alloca %struct.tm*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i16 0, i16* %6
%11 = call i32 (...) @co20_init()
%12 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
17: ; preds = %2
%18 = load i32*, i32** %10
%19 = load i32, i32* @_IONBF
%20 = call i32 @setvbuf(i32* %18, i32* null, i32 %19, i32 0)
br label %21
21: ; preds = %17, %21
%22 = call zeroext i16 (...) @co20_get_air_quality()
store i16 %22, i16* %6
%23 = call i32 @time(i32* %8)
%24 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %24, %struct.tm** %9
%25 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%26 = load %struct.tm*, %struct.tm** %9
%27 = call i32 @strftime(i8* %25, i32 26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %26)
%28 = load i32*, i32** %10
%29 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%30 = load i16, i16* %6
%31 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %29, i16 zeroext %30)
%32 = getelementptr inbounds [26 x i8], [26 x i8]* %7, i64 0, i64 0
%33 = load i16, i16* %6
%34 = zext i16 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %32, i32 %34)
%36 = call i32 @sleep(i32 2)
br label %21
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [8 x i8] c"air.csv\00"
@.str.1 = [2 x i8] c"a\00"
@_IONBF = global i32 0
@.str.3 = [18 x i8] c"%d.%m.%Y %H:%M:%S\00"
@.str.4 = [7 x i8] c"%s;%d\0A\00"
@str = [34 x i8] c"cannot open air.csv for appending\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [26 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 (...) @co20_init()
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
ret i32 1
12: ; preds = %2
%13 = load i32, i32* @_IONBF
%14 = tail call i32 @setvbuf(i32* %8, i32* null, i32 %13, i32 0)
br label %15
15: ; preds = %15, %12
%16 = call zeroext i16 (...) @co20_get_air_quality()
%17 = call i32 @time(i32* %4)
%18 = call %struct.tm* @localtime(i32* %4)
%19 = call i32 @strftime(i8* %5, i32 26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %18)
%20 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %5, i16 zeroext %16)
%21 = zext i16 %16 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %5, i32 %21)
%23 = call i32 @sleep(i32 2)
br label %15
}