#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 tm_year;
  int tm_mon;
  int tm_mday;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_min;
  int /*<<< orphan*/ tm_hour;
};
struct stat {
  int /*<<< orphan*/ st_mtime;
};

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/);
int stat(char *, struct stat *);
int get_mod_time(char s[], char fname[]) {
  struct tm *mytime;
  struct stat st;
  int r;
  r = stat(fname, &st);
  mytime = gmtime(&(st.st_mtime));
  if (r < 0)
    perror("stat");
  else
    sprintf(s, "%d%0.2d%0.2d%0.2d%0.2d%0.2d", mytime->tm_year,
            mytime->tm_mon + 1, mytime->tm_mday, mytime->tm_hour,
            mytime->tm_min, mytime->tm_sec);
  return r;
}


x86 assembly (clang, -O0):
<get_mod_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1188 <get_mod_time+0x48>
lea    0xe82(%rip),%rdi
call   1040 <perror@plt>
jmp    11cf <get_mod_time+0x8f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%eax
lea    0xe43(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mod_time>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rbx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <stat@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <gmtime@plt>
test   %ebp,%ebp
js     119f <get_mod_time+0x5f>
mov    (%rax),%edx
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    0x8(%rax),%r8d
mov    0x14(%rax),%r9d
mov    0x10(%rax),%ebx
mov    0xc(%rax),%eax
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
push   %rax
push   %rbx
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5a(%rip),%rdi
call   1040 <perror@plt>
jmp    1194 <get_mod_time+0x54>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
%struct.stat = type { i32 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [28 x i8] c"%d%0.2d%0.2d%0.2d%0.2d%0.2d\00"
define i32 @get_mod_time(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca %struct.stat
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @stat(i8* %8, %struct.stat* %6)
store i32 %9, i32* %7
%10 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%11 = call %struct.tm* @gmtime(i32* %10)
store %struct.tm* %11, %struct.tm** %5
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %38
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load %struct.tm*, %struct.tm** %5
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load %struct.tm*, %struct.tm** %5
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 1
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
%25 = load %struct.tm*, %struct.tm** %5
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 2
%27 = load i32, i32* %26
%28 = load %struct.tm*, %struct.tm** %5
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 5
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %5
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.tm*, %struct.tm** %5
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %24, i32 %27, i32 %30, i32 %33, i32 %36)
br label %38
38: ; preds = %16, %14
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [5 x i8] c"stat\00"
@.str.1 = [28 x i8] c"%d%0.2d%0.2d%0.2d%0.2d%0.2d\00"
define i32 @get_mod_time(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* %1, %struct.stat* %3)
%6 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%7 = call %struct.tm* @gmtime(i32* %6)
%8 = icmp slt i32 %5, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %26
11: ; preds = %2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 5
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 4
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 3
%24 = load i32, i32* %23
%25 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %16, i32 %18, i32 %20, i32 %22, i32 %24)
br label %26
26: ; preds = %11, %9
ret i32 %5
}