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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ erreur_grave(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct passwd *getpwuid(int /*<<< orphan*/);
struct stat *malloc(int);
int /*<<< orphan*/ printf(char *, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct stat *buffer = malloc(sizeof(struct stat));
  int r;
  if (argc != 2) {
    fprintf(stderr, "Bad usage : %s <file_path>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  r = stat(argv[1], buffer);
  if (r < 0)
    erreur_grave("Stat");
  struct passwd *pw = getpwuid(buffer->st_uid);
  if (pw == NULL)
    erreur_grave("getpwuid failure");
  printf("Fichier %s:  mode: %X  Taille: %ld  Proprietaire: %s\n", argv[1],
         buffer->st_mode, buffer->st_size, pw->pw_name);
  exit(EXIT_SUCCESS);
}


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    $0xc,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c8 <main+0x58>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f2 <main+0x82>
lea    0xe2f(%rip),%rdi
call   1070 <erreur_grave@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1219 <main+0xa9>
lea    0xe0d(%rip),%rdi
call   1070 <erreur_grave@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8d
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0xc,%edi
call   1080 <malloc@plt>
cmp    $0x2,%ebp
jne    11ec <main+0x7c>
mov    %rax,%rbx
mov    0x8(%r14),%rdi
mov    %rax,%rsi
call   1060 <stat@plt>
test   %eax,%eax
jns    11aa <main+0x3a>
lea    0xe77(%rip),%rdi
call   1070 <erreur_grave@plt>
mov    0x8(%rbx),%edi
call   1030 <getpwuid@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11c6 <main+0x56>
lea    0xe60(%rip),%rdi
call   1070 <erreur_grave@plt>
mov    0x8(%r14),%rsi
mov    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    (%r15),%r8d
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"Bad usage : %s <file_path>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"Stat\00"
@.str.2 = [17 x i8] c"getpwuid failure\00"
@.str.3 = [54 x i8] c"Fichier %s: mode: %X Taille: %ld Proprietaire: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat*
%7 = alloca i32
%8 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call %struct.stat* @malloc(i32 12)
store %struct.stat* %9, %struct.stat** %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load %struct.stat*, %struct.stat** %6
%25 = call i32 @stat(i8* %23, %struct.stat* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @erreur_grave(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %20
%31 = load %struct.stat*, %struct.stat** %6
%32 = getelementptr inbounds %struct.stat, %struct.stat* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = call %struct.passwd* @getpwuid(i32 %33)
store %struct.passwd* %34, %struct.passwd** %8
%35 = load %struct.passwd*, %struct.passwd** %8
%36 = icmp eq %struct.passwd* %35, null
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @erreur_grave(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %30
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = load %struct.stat*, %struct.stat** %6
%44 = getelementptr inbounds %struct.stat, %struct.stat* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load %struct.stat*, %struct.stat** %6
%47 = getelementptr inbounds %struct.stat, %struct.stat* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load %struct.passwd*, %struct.passwd** %8
%50 = getelementptr inbounds %struct.passwd, %struct.passwd* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32 %45, i32 %48, i32 %51)
%53 = load i32, i32* @EXIT_SUCCESS
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.passwd = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"Bad usage : %s <file_path>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"Stat\00"
@.str.2 = [17 x i8] c"getpwuid failure\00"
@.str.3 = [54 x i8] c"Fichier %s: mode: %X Taille: %ld Proprietaire: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call %struct.stat* @malloc(i32 12)
%4 = icmp eq i32 %0, 2
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @stat(i8* %13, %struct.stat* %3)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @erreur_grave(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%20 = load i32, i32* %19
%21 = tail call %struct.passwd* @getpwuid(i32 %20)
%22 = icmp eq %struct.passwd* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @erreur_grave(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = load i8*, i8** %12
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i64 0, i32 0
%32 = load i32, i32* %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %26, i32 %28, i32 %30, i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
%35 = tail call i32 @exit(i32 %34)
unreachable
}