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

/* Variables and functions */
int S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ failInfo(int, char *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
void getFileInfo(char *path) {
  int ret;
  struct stat info;
  struct tm *p;
  ret = stat(path, &info);
  if (ret == -1) {
    failInfo(1, "can't stat file\n");
  } else {
    p = localtime(&(info.st_mtime));
    printf("<rsp state=\"ok\"><return ");
    printf("filesize=\"%d\" ", (int)info.st_size);
    printf("mode=\"%d\" ", S_ISDIR(info.st_mode));
    printf("year=\"%d\" ", p->tm_year + 1900);
    printf("mon=\"%d\" ", p->tm_mon + 1);
    printf("mday=\"%d\" ", p->tm_mday);
    printf("/></rsp>");
  }
}


x86 assembly (clang, -O0):
<getFileInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    118c <getFileInfo+0x3c>
mov    $0x1,%edi
lea    0xe7e(%rip),%rsi
call   1040 <failInfo@plt>
jmp    122c <getFileInfo+0xdc>
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%edi
call   1060 <S_ISDIR@plt>
mov    %eax,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
add    $0x76c,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
add    $0x1,%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileInfo>:
push   %rbx
sub    $0x20,%rsp
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     11fc <getFileInfo+0xac>
lea    0x18(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x76c,%esi
add    (%rbx),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
add    $0x1,%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%esi
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdfd(%rip),%rsi
mov    $0x1,%edi
add    $0x20,%rsp
pop    %rbx
jmp    1040 <failInfo@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [17 x i8] c"can't stat file\0A\00"
@.str.1 = [25 x i8] c"<rsp state=\22ok\22><return \00"
@.str.2 = [15 x i8] c"filesize=\22%d\22 \00"
@.str.3 = [11 x i8] c"mode=\22%d\22 \00"
@.str.4 = [11 x i8] c"year=\22%d\22 \00"
@.str.5 = [10 x i8] c"mon=\22%d\22 \00"
@.str.6 = [11 x i8] c"mday=\22%d\22 \00"
@.str.7 = [9 x i8] c"/></rsp>\00"
define void @getFileInfo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca %struct.tm*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @stat(i8* %6, %struct.stat* %4)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @failInfo(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %39
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 2
%14 = call %struct.tm* @localtime(i32* %13)
store %struct.tm* %14, %struct.tm** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISDIR(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load %struct.tm*, %struct.tm** %5
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1900
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load %struct.tm*, %struct.tm** %5
%30 = getelementptr inbounds %struct.tm, %struct.tm* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = load %struct.tm*, %struct.tm** %5
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %39
39: ; preds = %12, %10
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i64, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [17 x i8] c"can't stat file\0A\00"
@.str.1 = [25 x i8] c"<rsp state=\22ok\22><return \00"
@.str.2 = [15 x i8] c"filesize=\22%d\22 \00"
@.str.3 = [11 x i8] c"mode=\22%d\22 \00"
@.str.4 = [11 x i8] c"year=\22%d\22 \00"
@.str.5 = [10 x i8] c"mon=\22%d\22 \00"
@.str.6 = [11 x i8] c"mday=\22%d\22 \00"
@.str.7 = [9 x i8] c"/></rsp>\00"
define void @getFileInfo(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @failInfo(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %32
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%10 = call %struct.tm* @localtime(i32* %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISDIR(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 1
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %8, %6
ret void
}