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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int, int,
                           int /*<<< orphan*/);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strftime(char *, int const, char *, struct tm *);
int main(int argc, char **argv) {
  const char *fname = "stat.c";
  struct stat fstat;
  if (stat(fname, &fstat) == 0) {
    fprintf(stdout, "Name: %s, UID: %u, GID: %u, Size: %llu\n", fname,
            fstat.st_uid, fstat.st_gid, fstat.st_size);
    const static int bufSize = 128;
    char buf[bufSize];
    struct tm mtime = *gmtime(&fstat.st_mtime);
    strftime(buf, bufSize, "%Y-%m-%d %H:%M:%S %Z", &mtime);
    printf("Last modified: %s\n", buf);
  } else {
    perror("Couldn't stat file.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1218 <main+0xb8>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe50(%rip),%rsi
call   1040 <fprintf@plt>
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rax
add    $0xffffffffffffff80,%rax
mov    %rax,-0x40(%rbp)
mov    %rax,%rsp
lea    -0x28(%rbp),%rdi
add    $0x8,%rdi
call   1080 <gmtime@plt>
mov    -0x40(%rbp),%rdi
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x80,%esi
lea    0xe3c(%rip),%rdx
lea    -0x38(%rbp),%rcx
call   1060 <strftime@plt>
mov    -0x40(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    1224 <main+0xc4>
lea    0xe38(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe8e(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
jne    11f5 <main+0x95>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
lea    0xe6c(%rip),%rsi
lea    0xe5e(%rip),%rdx
call   1040 <fprintf@plt>
mov    %rsp,%r14
lea    -0x80(%rsp),%rbx
mov    %rbx,%rsp
lea    -0x20(%rbp),%rdi
call   1080 <gmtime@plt>
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe68(%rip),%rdx
lea    -0x18(%rbp),%rcx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <strftime@plt>
lea    0xe65(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rsp
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
jmp    11ea <main+0x8a>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32 }
%struct.tm = type { i32 }
@.str = [7 x i8] c"stat.c\00"
@stdout = global i32 0
@.str.1 = [40 x i8] c"Name: %s, UID: %u, GID: %u, Size: %llu\0A\00"
@main.bufSize = internal constant i32 128
@.str.2 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.3 = [19 x i8] c"Last modified: %s\0A\00"
@.str.4 = [21 x i8] c"Couldn't stat file.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca %struct.tm
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = load i8*, i8** %6
%11 = call i64 @stat(i8* %10, %struct.stat* %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = load i8*, i8** %6
%16 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 3
%21 = load i32, i32* %20
%22 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %17, i32 %19, i32 %21)
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %8
%24 = alloca i8, i64 128
%25 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 2
%26 = call %struct.tm* @gmtime(i32* %25)
%27 = bitcast %struct.tm* %9 to i8*
%28 = bitcast %struct.tm* %26 to i8*
%29 = call i32 @strftime(i8* %24, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %9)
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%31 = load i8*, i8** %8
br label %34
32: ; preds = %2
%33 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %13
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32 }
%struct.tm = type { i32 }
@.str = [7 x i8] c"stat.c\00"
@stdout = global i32 0
@.str.1 = [40 x i8] c"Name: %s, UID: %u, GID: %u, Size: %llu\0A\00"
@.str.2 = [21 x i8] c"%Y-%m-%d %H:%M:%S %Z\00"
@.str.3 = [19 x i8] c"Last modified: %s\0A\00"
@.str.4 = [21 x i8] c"Couldn't stat file.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.tm
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i64 @stat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = load i32, i32* @stdout
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 3
%15 = load i32, i32* %14
%16 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13, i32 %15)
%17 = call i8* @llvm.stacksave()
%18 = alloca [128 x i8]
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %18, i64 0, i64 0
%20 = bitcast %struct.tm* %4 to i8*
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%22 = call %struct.tm* @gmtime(i32* %21)
%23 = getelementptr %struct.tm, %struct.tm* %22, i64 0, i32 0
%24 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%25 = load i32, i32* %23
store i32 %25, i32* %24
%26 = call i32 @strftime(i8* %19, i32 128, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %4)
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %30
28: ; preds = %2
%29 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %8
ret i32 0
}