#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*/ uri;
typedef int /*<<< orphan*/ time;
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ protocol;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *default_uri(const char *app_name, const char *name, const char *domain) {
  static char uri[256];
  int remaining = sizeof(uri) - 1;
  char *protocol = "file:";
  char time[25];
  struct timeval tv;
  gettimeofday(&tv, NULL);
  strftime(time, sizeof(time), "%Y-%m-%dt%H.%M.%S%z", localtime(&tv.tv_sec));
  *uri = 0;
  strncat(uri, protocol, remaining);
  remaining -= sizeof(protocol);
  strncat(uri, app_name, remaining);
  remaining -= strlen(app_name);
  if (name) {
    strncat(uri, "_", remaining);
    remaining--;
    strncat(uri, name, remaining);
    remaining -= strlen(name);
  }
  if (domain) {
    strncat(uri, "_", remaining);
    remaining--;
    strncat(uri, domain, remaining);
  }
  strncat(uri, "_", remaining);
  remaining--;
  strncat(uri, time, remaining);
  return uri;
}


x86 assembly (clang, -O0):
<default_uri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xff,-0x1c(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x58(%rbp),%rdi
call   1030 <localtime@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%ecx
mov    $0x19,%esi
lea    0xe60(%rip),%rdx
call   1070 <strftime@plt>
movb   $0x0,0x2eae(%rip)
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2ea0(%rip),%rdi
call   1060 <strncat@plt>
movslq -0x1c(%rbp),%rax
sub    $0x8,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2e82(%rip),%rdi
call   1060 <strncat@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     124c <default_uri+0xfc>
mov    -0x1c(%rbp),%edx
lea    0x2e52(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2e2f(%rip),%rdi
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1289 <default_uri+0x139>
mov    -0x1c(%rbp),%edx
lea    0x2dff(%rip),%rdi
lea    0xdb2(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2ddc(%rip),%rdi
call   1060 <strncat@plt>
mov    -0x1c(%rbp),%edx
lea    0x2dcd(%rip),%rdi
lea    0xd80(%rip),%rsi
call   1060 <strncat@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
lea    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0x2daa(%rip),%rdi
call   1060 <strncat@plt>
lea    0x2d9e(%rip),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_uri>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %rbp,%rdi
call   1030 <localtime@plt>
lea    0xe83(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x19,%esi
mov    %eax,%ecx
call   1070 <strftime@plt>
movb   $0x0,0x2ec5(%rip)
lea    0x2ebe(%rip),%r12
lea    0xe57(%rip),%rsi
mov    %r12,%rdi
mov    $0xff,%edx
call   1060 <strncat@plt>
mov    $0xf7,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xf7,%edx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
sub    %ebx,%ebp
test   %r15,%r15
je     1213 <default_uri+0xc3>
lea    0x2e7c(%rip),%r12
lea    0xe2f(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    $0xf6,%ebp
sub    %ebx,%ebp
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
test   %r14,%r14
je     1240 <default_uri+0xf0>
lea    0x2e41(%rip),%rbx
lea    0xdf4(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <strncat@plt>
lea    0x2e19(%rip),%rbx
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
add    $0xffffffff,%ebp
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@default_uri.uri = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"file:\00"
@.str.1 = [20 x i8] c"%Y-%m-%dt%H.%M.%S%z\00"
@.str.2 = [2 x i8] c"_\00"
define i8* @default_uri(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [25 x i8]
%10 = alloca %struct.timeval
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 255, i32* %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%12 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%14 = call i32 @localtime(i32* %13)
%15 = call i32 @strftime(i8* %12, i32 25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0)
%16 = load i8*, i8** %8
%17 = load i32, i32* %7
%18 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %16, i32 %17)
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = sub i64 %20, 8
%22 = trunc i64 %21 to i32
store i32 %22, i32* %7
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %23, i32 %24)
%26 = load i8*, i8** %4
%27 = call i64 @strlen(i8* %26)
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = sub nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %48
34: ; preds = %3
%35 = load i32, i32* %7
%36 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = add nsw i32 %37, -1
store i32 %38, i32* %7
%39 = load i8*, i8** %5
%40 = load i32, i32* %7
%41 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %39, i32 %40)
%42 = load i8*, i8** %5
%43 = call i64 @strlen(i8* %42)
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = sub nsw i64 %45, %43
%47 = trunc i64 %46 to i32
store i32 %47, i32* %7
br label %48
48: ; preds = %34, %3
%49 = load i8*, i8** %6
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %59
51: ; preds = %48
%52 = load i32, i32* %7
%53 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
%56 = load i8*, i8** %6
%57 = load i32, i32* %7
%58 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %56, i32 %57)
br label %59
59: ; preds = %51, %48
%60 = load i32, i32* %7
%61 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %7
%63 = add nsw i32 %62, -1
store i32 %63, i32* %7
%64 = getelementptr inbounds [25 x i8], [25 x i8]* %9, i64 0, i64 0
%65 = load i32, i32* %7
%66 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %64, i32 %65)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@default_uri.uri = internal global [256 x i8] zeroinitializer
@.str = [6 x i8] c"file:\00"
@.str.1 = [20 x i8] c"%Y-%m-%dt%H.%M.%S%z\00"
@.str.2 = [2 x i8] c"_\00"
define i8* @default_uri(i8* %0, i8* %1, i8* %2) {
%4 = alloca [25 x i8]
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%7 = bitcast %struct.timeval* %5 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%10 = call i32 @localtime(i32* %9)
%11 = call i32 @strftime(i8* %6, i32 25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0)
%12 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 255)
%13 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %0, i32 247)
%14 = call i64 @strlen(i8* dereferenceable(1) %0)
%15 = trunc i64 %14 to i32
%16 = sub i32 247, %15
%17 = icmp eq i8* %1, null
br i1 %17, label %25, label %18
18: ; preds = %3
%19 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%20 = sub i32 246, %15
%21 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %1, i32 %20)
%22 = call i64 @strlen(i8* %1)
%23 = trunc i64 %22 to i32
%24 = sub i32 %20, %23
br label %25
25: ; preds = %18, %3
%26 = phi i32 [ %24, %18 ], [ %16, %3 ]
%27 = icmp eq i8* %2, null
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%30 = add nsw i32 %26, -1
%31 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %2, i32 %30)
br label %32
32: ; preds = %28, %25
%33 = phi i32 [ %30, %28 ], [ %26, %25 ]
%34 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = add nsw i32 %33, -1
%36 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0), i8* %6, i32 %35)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @default_uri.uri, i64 0, i64 0)
}