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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void grava_data() {
  char tempo[8], data[8];
  FILE *p;
  p = fopen("timeini.txt", "r+");
  if (p == NULL) {
    int dia, mes, ano;
    p = fopen("timeini.txt", "w");
    struct tm *local;
    time_t t;
    t = time(NULL);
    local = localtime(&t);
    dia = local->tm_mday;
    mes = local->tm_mon + 1;
    ano = local->tm_year + 1900;
    fprintf(p, "%d/%d/%d %s", dia, mes, ano, "14:53:22");
  } else {
    fscanf(p,
           "%s"
           "%s",
           data, tempo);
    printf("Você ja comecou o teste, no dia %s, as %s\n", data, tempo);
  }
  fclose(p);
}


x86 assembly (clang, -O0):
<grava_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1215 <grava_data+0xa5>
lea    0xe5f(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x34(%rbp)
lea    -0x34(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe0d(%rip),%rsi
lea    0xe12(%rip),%r9
call   1070 <fprintf@plt>
jmp    1241 <grava_data+0xd1>
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rdx
lea    -0x8(%rbp),%rcx
lea    0xdfe(%rip),%rsi
call   1060 <fscanf@plt>
lea    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    0xdef(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grava_data>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11c5 <grava_data+0x55>
mov    %rax,%rbx
lea    0xe8b(%rip),%rsi
lea    0x8(%rsp),%r14
mov    %rsp,%r15
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <fscanf@plt>
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <printf@plt>
jmp    1215 <grava_data+0xa5>
lea    0xe34(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,(%rsp)
mov    %rsp,%rdi
call   1030 <localtime@plt>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    $0x76c,%r8d
add    0x8(%rax),%r8d
lea    0xe0b(%rip),%rsi
lea    0xe10(%rip),%r9
mov    %rbx,%rdi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [12 x i8] c"timeini.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [12 x i8] c"%d/%d/%d %s\00"
@.str.4 = [9 x i8] c"14:53:22\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [44 x i8] c"Voc\C3\AA ja comecou o teste, no dia %s, as %s\0A\00"
define void @grava_data() {
%1 = alloca [8 x i8]
%2 = alloca [8 x i8]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca i32
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %32
12: ; preds = %0
%13 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %3
%14 = call i32 @time(i32* null)
store i32 %14, i32* %8
%15 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %15, %struct.tm** %7
%16 = load %struct.tm*, %struct.tm** %7
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %4
%19 = load %struct.tm*, %struct.tm** %7
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
%23 = load %struct.tm*, %struct.tm** %7
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1900
store i32 %26, i32* %6
%27 = load i32*, i32** %3
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %29, i32 %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %40
32: ; preds = %0
%33 = load i32*, i32** %3
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%36 = call i32 @fscanf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %34, i8* %35)
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%39 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %37, i8* %38)
br label %40
40: ; preds = %32, %12
%41 = load i32*, i32** %3
%42 = call i32 @fclose(i32* %41)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [12 x i8] c"timeini.txt\00"
@.str.1 = [3 x i8] c"r+\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [12 x i8] c"%d/%d/%d %s\00"
@.str.4 = [9 x i8] c"14:53:22\00"
@.str.5 = [5 x i8] c"%s%s\00"
@.str.6 = [44 x i8] c"Voc\C3\AA ja comecou o teste, no dia %s, as %s\0A\00"
define void @grava_data() {
%1 = alloca [8 x i8]
%2 = alloca [8 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = bitcast i32* %3 to i8*
%11 = tail call i32 @time(i32* null)
store i32 %11, i32* %3
%12 = call %struct.tm* @localtime(i32* %3)
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 2
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1900
%21 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %17, i32 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %25
22: ; preds = %0
%23 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %5, i8* %4)
%24 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %5, i8* %4)
br label %25
25: ; preds = %22, %8
%26 = phi i32* [ %9, %8 ], [ %6, %22 ]
%27 = call i32 @fclose(i32* %26)
ret void
}