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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
struct tm *localtime(long *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(long *);
int gl_dupelog_add(char *rel) {
  FILE *f;
  char timebuf[50];
  long now;
  struct tm *tm;
  time(&now);
  tm = localtime(&now);
  if (!tm)
    return 0;
  strftime(timebuf, 50, "%m%d%g", tm);
  f = fopen("/ftp-data/logs/dupelog", "a");
  if (!f)
    return 0;
  fprintf(f, "%s %s\n", timebuf, rel);
  fclose(f);
  return 1;
}


x86 assembly (clang, -O0):
<gl_dupelog_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x58(%rbp),%rdi
call   1060 <time@plt>
lea    -0x58(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1199 <gl_dupelog_add+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1208 <gl_dupelog_add+0xa8>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rcx
mov    $0x32,%esi
lea    0xe53(%rip),%rdx
call   1070 <strftime@plt>
lea    0xe4e(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <gl_dupelog_add+0x80>
movl   $0x0,-0x4(%rbp)
jmp    1208 <gl_dupelog_add+0xa8>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe2d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gl_dupelog_add>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11df <gl_dupelog_add+0x7f>
lea    0xe72(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x32,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
lea    0xe60(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11df <gl_dupelog_add+0x7f>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%m%d%g\00"
@.str.1 = [23 x i8] c"/ftp-data/logs/dupelog\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define i32 @gl_dupelog_add(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [50 x i8]
%6 = alloca i64
%7 = alloca %struct.tm*
store i8* %0, i8** %3
%8 = call i32 @time(i64* %6)
%9 = call %struct.tm* @localtime(i64* %6)
store %struct.tm* %9, %struct.tm** %7
%10 = load %struct.tm*, %struct.tm** %7
%11 = icmp ne %struct.tm* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %28
13: ; preds = %1
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%15 = load %struct.tm*, %struct.tm** %7
%16 = call i32 @strftime(i8* %14, i32 50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %15)
%17 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %4
%18 = load i32*, i32** %4
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 0, i32* %2
br label %28
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%24 = load i8*, i8** %3
%25 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
store i32 1, i32* %2
br label %28
28: ; preds = %21, %20, %12
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%m%d%g\00"
@.str.1 = [23 x i8] c"/ftp-data/logs/dupelog\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [7 x i8] c"%s %s\0A\00"
define i32 @gl_dupelog_add(i8* %0) {
%2 = alloca [50 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = bitcast i64* %3 to i8*
%6 = call i32 @time(i64* %3)
%7 = call %struct.tm* @localtime(i64* %3)
%8 = icmp eq %struct.tm* %7, null
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = call i32 @strftime(i8* %4, i32 50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %7)
%11 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %0)
%15 = call i32 @fclose(i32* %11)
br label %16
16: ; preds = %9, %1, %13
%17 = phi i32 [ 1, %13 ], [ 0, %1 ], [ 0, %9 ]
ret i32 %17
}