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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ log_error(char *, char const *, ...);
char *malloc(int);
char *printDate(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int strlen(char const *);
int save_result(time_t date, int resultat, const char *tache, char *logdir) {
  char *stringResult;
  char *ficlog;
  FILE *flog = NULL;
  if (!resultat) {
    stringResult = "OK";
  } else {
    stringResult = "FAIL";
  }
  ficlog = malloc(sizeof(char) * (strlen(logdir) + strlen(tache) + 2));
  if (ficlog == NULL) {
    log_error(
        "Task %s could not allocate memory. Task's result won't be saved.",
        tache);
    return 1;
  }
  sprintf(ficlog, "%s/%s", logdir, tache);
  flog = fopen(ficlog, "a");
  free(ficlog);
  if (flog == NULL) {
    log_error("Task %s could not create or modify the file %s. Task's result "
              "won't be saved.",
              tache, ficlog);
    return 2;
  }
  fseek(flog, 0, SEEK_END);
  if (!ftell(flog)) {
    fprintf(flog, "date;result\n");
  }
  fprintf(flog, "%s;%s\n", printDate(date), stringResult);
  fclose(flog);
  return 0;
}


x86 assembly (clang, -O0):
<save_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11e8 <save_result+0x38>
lea    0xe21(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11f3 <save_result+0x43>
lea    0xe14(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124c <save_result+0x9c>
mov    -0x18(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <log_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    131f <save_result+0x16f>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdea(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xde0(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
jne    12ae <save_result+0xfe>
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1050 <log_error@plt>
movl   $0x2,-0x4(%rbp)
jmp    131f <save_result+0x16f>
mov    -0x38(%rbp),%rdi
mov    0x2d2f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x38(%rbp),%rdi
call   1080 <ftell@plt>
cmp    $0x0,%eax
jne    12e6 <save_result+0x136>
mov    -0x38(%rbp),%rdi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%edi
call   10b0 <printDate@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_result>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %edi,%r14d
test   %esi,%esi
lea    0xe26(%rip),%rax
lea    0xe22(%rip),%r15
cmove  %rax,%r15
mov    %rcx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12a5 <save_result+0xe5>
mov    %rax,%rbp
lea    0xe34(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
call   10d0 <sprintf@plt>
lea    0xe25(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
je     12bd <save_result+0xfd>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
test   %eax,%eax
jne    127c <save_result+0xbc>
lea    0xe35(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
mov    %r14d,%edi
call   10b0 <printDate@plt>
lea    0xe21(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    12d6 <save_result+0x116>
lea    0xd5c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <log_error@plt>
mov    $0x1,%ebp
jmp    12d6 <save_result+0x116>
lea    0xd8d(%rip),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <log_error@plt>
mov    $0x2,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"OK\00"
@.str.1 = [5 x i8] c"FAIL\00"
@.str.2 = [65 x i8] c"Task %s could not allocate memory. Task's result won't be saved.\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [78 x i8] c"Task %s could not create or modify the file %s. Task's result won't be saved.\00"
@SEEK_END = global i32 0
@.str.6 = [13 x i8] c"date;result\0A\00"
@.str.7 = [7 x i8] c"%s;%s\0A\00"
define i32 @save_result(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32* null, i32** %12
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10
br label %17
16: ; preds = %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %17
17: ; preds = %16, %15
%18 = load i8*, i8** %9
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %8
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %19, %21
%23 = add nsw i32 %22, 2
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %11
%28 = load i8*, i8** %11
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %17
%31 = load i8*, i8** %8
%32 = call i32 (i8*, i8*, ...) @log_error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 1, i32* %5
br label %66
33: ; preds = %17
%34 = load i8*, i8** %11
%35 = load i8*, i8** %9
%36 = load i8*, i8** %8
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %36)
%38 = load i8*, i8** %11
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %39, i32** %12
%40 = load i8*, i8** %11
%41 = call i32 @free(i8* %40)
%42 = load i32*, i32** %12
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %33
%45 = load i8*, i8** %8
%46 = load i8*, i8** %11
%47 = call i32 (i8*, i8*, ...) @log_error(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.5, i64 0, i64 0), i8* %45, i8* %46)
store i32 2, i32* %5
br label %66
48: ; preds = %33
%49 = load i32*, i32** %12
%50 = load i32, i32* @SEEK_END
%51 = call i32 @fseek(i32* %49, i32 0, i32 %50)
%52 = load i32*, i32** %12
%53 = call i32 @ftell(i32* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %48
%56 = load i32*, i32** %12
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %55, %48
%59 = load i32*, i32** %12
%60 = load i32, i32* %6
%61 = call i8* @printDate(i32 %60)
%62 = load i8*, i8** %10
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %61, i8* %62)
%64 = load i32*, i32** %12
%65 = call i32 @fclose(i32* %64)
store i32 0, i32* %5
br label %66
66: ; preds = %58, %44, %30
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
@.str = [3 x i8] c"OK\00"
@.str.1 = [5 x i8] c"FAIL\00"
@.str.2 = [65 x i8] c"Task %s could not allocate memory. Task's result won't be saved.\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [78 x i8] c"Task %s could not create or modify the file %s. Task's result won't be saved.\00"
@SEEK_END = global i32 0
@.str.6 = [13 x i8] c"date;result\0A\00"
@.str.7 = [7 x i8] c"%s;%s\0A\00"
define i32 @save_result(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = icmp eq i32 %1, 0
%6 = select i1 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%7 = tail call i32 @strlen(i8* %3)
%8 = tail call i32 @strlen(i8* %2)
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 (i8*, i8*, ...) @log_error(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %33
15: ; preds = %4
%16 = tail call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %2)
%17 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @free(i8* %11)
%19 = icmp eq i32* %17, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 (i8*, i8*, ...) @log_error(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* %11)
br label %33
22: ; preds = %15
%23 = load i32, i32* @SEEK_END
%24 = tail call i32 @fseek(i32* %17, i32 0, i32 %23)
%25 = tail call i32 @ftell(i32* %17)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 12, i64 1, i32* %17)
br label %29
29: ; preds = %27, %22
%30 = tail call i8* @printDate(i32 %0)
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %30, i8* %6)
%32 = tail call i32 @fclose(i32* %17)
br label %33
33: ; preds = %29, %20, %13
%34 = phi i32 [ 1, %13 ], [ 2, %20 ], [ 0, %29 ]
ret i32 %34
}