#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 */
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
char *get_timestamp();
int open(char *, int, int);
size_t strlen(char *);
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char *argv[]) {
  char *filename = argv[1];
  char *timestamp = get_timestamp();
  int fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0666);
  size_t length = strlen(timestamp);
  write(fd, timestamp, length);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <get_timestamp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
or     (%rax),%esi
mov    0x2e2e(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%r14
xor    %eax,%eax
call   1060 <get_timestamp@plt>
mov    0x2e6a(%rip),%rcx
mov    0x2e8b(%rip),%rdx
mov    (%rdx),%esi
or     (%rcx),%esi
mov    %rax,%rbx
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = call i8* (...) @get_timestamp()
store i8* %13, i8** %7
%14 = load i8*, i8** %6
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_APPEND
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %14, i32 %19, i32 438)
store i32 %20, i32* %8
%21 = load i8*, i8** %7
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* %9
%23 = load i32, i32* %8
%24 = load i8*, i8** %7
%25 = load i64, i64* %9
%26 = call i32 @write(i32 %23, i8* %24, i64 %25)
%27 = load i32, i32* %8
%28 = call i32 @close(i32 %27)
ret i32 0
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i8* (...) @get_timestamp()
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_APPEND
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* %4, i32 %10, i32 438)
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%13 = tail call i32 @write(i32 %11, i8* %5, i64 %12)
%14 = tail call i32 @close(i32 %11)
ret i32 0
}