#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;
struct stat {
  int /*<<< orphan*/ st_mtime;
};

/* Variables and functions */
int stat(char const *, struct stat *);
int get_timestamp(const char *path, time_t *timestamp) {
  struct stat s;
  int val;
  if (!path)
    return -1;
  if (!timestamp)
    return -1;
  *timestamp = 0;
  val = stat(path, &s);
  if (val)
    return -1;
  *timestamp = s.st_mtime;
  return 0;
}


x86 assembly (clang, -O0):
<get_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <get_timestamp+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <get_timestamp+0x7e>
cmpq   $0x0,-0x18(%rbp)
jne    114e <get_timestamp+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <get_timestamp+0x7e>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     117e <get_timestamp+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <get_timestamp+0x7e>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timestamp>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     113e <get_timestamp+0x2e>
mov    %rsi,%rbx
test   %rsi,%rsi
je     113e <get_timestamp+0x2e>
movl   $0x0,(%rbx)
mov    %rsp,%rsi
call   1030 <stat@plt>
test   %eax,%eax
jne    113e <get_timestamp+0x2e>
mov    (%rsp),%eax
mov    %eax,(%rbx)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @get_timestamp(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.stat
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 -1, i32* %3
br label %26
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11
store i32 -1, i32* %3
br label %26
15: ; preds = %11
%16 = load i32*, i32** %5
store i32 0, i32* %16
%17 = load i8*, i8** %4
%18 = call i32 @stat(i8* %17, %struct.stat* %6)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %3
br label %26
22: ; preds = %15
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32*, i32** %5
store i32 %24, i32* %25
store i32 0, i32* %3
br label %26
26: ; preds = %22, %21, %14, %10
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @get_timestamp(i8* %0, i32* writeonly %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq i32* %1, null
%7 = or i1 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %2
store i32 0, i32* %1
%9 = call i32 @stat(i8* %0, %struct.stat* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %1
br label %14
14: ; preds = %8, %2, %11
%15 = phi i32 [ 0, %11 ], [ -1, %2 ], [ -1, %8 ]
ret i32 %15
}