#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 */

/* Variables and functions */
unsigned int getpid();
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, unsigned int,
                            unsigned int);
unsigned int time(int /*<<< orphan*/ *);
char *generate_filename(unsigned int nr) {
  char *fn = malloc(48);
  unsigned int t, p;
  if (NULL != fn) {
    t = time(NULL);
    p = getpid();
    snprintf(fn, 48,
             "/var/run/smime-gate"
             "/mail%d_%d-%d",
             t, p, nr);
  }
  return fn;
}


x86 assembly (clang, -O0):
<generate_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x30,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     119b <generate_filename+0x5b>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x4(%rbp),%r9d
mov    $0x30,%esi
lea    0xe6a(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_filename>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x30,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1185 <generate_filename+0x45>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe90(%rip),%rdx
mov    %rbx,%rdi
mov    $0x30,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
mov    %r14d,%r9d
call   1040 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"/var/run/smime-gate/mail%d_%d-%d\00"
define i8* @generate_filename(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i8* @malloc(i32 48)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* null, %7
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = call i32 @time(i32* null)
store i32 %10, i32* %4
%11 = call i32 (...) @getpid()
store i32 %11, i32* %5
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = call i32 @snprintf(i8* %12, i32 48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14, i32 %15)
br label %17
17: ; preds = %9, %1
%18 = load i8*, i8** %3
ret i8* %18
}

LLVM IR (-O2):
@.str = [33 x i8] c"/var/run/smime-gate/mail%d_%d-%d\00"
define i8* @generate_filename(i32 %0) {
%2 = tail call dereferenceable_or_null(48) i8* @malloc(i32 48)
%3 = icmp eq i8* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 @snprintf(i8* %2, i32 48, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %0)
br label %8
8: ; preds = %4, %1
ret i8* %2
}