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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ erreur_grave(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct passwd *getpwuid(int);
int /*<<< orphan*/ printf(char *, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int stat(char *, struct stat *);
int main(int argc, char **argv) {
  struct stat status;
  struct stat *buffer = &status;
  int r;
  r = stat(argv[1], buffer);
  if (r < 0)
    erreur_grave("Stat");
  struct passwd *user = getpwuid(buffer->st_uid);
  if (!user)
    erreur_grave("Getpwuid");
  struct passwd *user_fake = getpwuid(1000);
  if (!user_fake)
    erreur_grave("Getpwuid fake");
  printf("Fichier %s:  mode: %X  Taille: %ld  Proprietaire: %s\n", argv[1],
         buffer->st_mode, buffer->st_size, user->pw_name);
  exit(EXIT_SUCCESS);
}


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    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1198 <main+0x48>
lea    0xe6d(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11be <main+0x6e>
lea    0xe4c(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    $0x3e8,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e3 <main+0x93>
lea    0xe30(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x38(%rbp),%rax
mov    (%rax),%r8d
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %eax,%eax
jns    1178 <main+0x28>
lea    0xe8d(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    0x8(%rsp),%edi
call   1030 <getpwuid@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1195 <main+0x45>
lea    0xe75(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    $0x3e8,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
jne    11b0 <main+0x60>
lea    0xe63(%rip),%rdi
call   1060 <erreur_grave@plt>
mov    0x8(%r14),%rsi
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    (%rbx),%r8d
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
%struct.passwd = type { i32 }
@.str = [5 x i8] c"Stat\00"
@.str.1 = [9 x i8] c"Getpwuid\00"
@.str.2 = [14 x i8] c"Getpwuid fake\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 %struct.stat*
%8 = alloca i32
%9 = alloca %struct.passwd*
%10 = alloca %struct.passwd*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.stat* %6, %struct.stat** %7
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load %struct.stat*, %struct.stat** %7
%15 = call i32 @stat(i8* %13, %struct.stat* %14)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @erreur_grave(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = load %struct.stat*, %struct.stat** %7
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call %struct.passwd* @getpwuid(i32 %23)
store %struct.passwd* %24, %struct.passwd** %9
%25 = load %struct.passwd*, %struct.passwd** %9
%26 = icmp ne %struct.passwd* %25, null
br i1 %26, label %29, label %27
27: ; preds = %20
%28 = call i32 @erreur_grave(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
%30 = call %struct.passwd* @getpwuid(i32 1000)
store %struct.passwd* %30, %struct.passwd** %10
%31 = load %struct.passwd*, %struct.passwd** %10
%32 = icmp ne %struct.passwd* %31, null
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @erreur_grave(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load %struct.stat*, %struct.stat** %7
%40 = getelementptr inbounds %struct.stat, %struct.stat* %39, i32 0, i32 1
%41 = load i32, i32* %40
%42 = load %struct.stat*, %struct.stat** %7
%43 = getelementptr inbounds %struct.stat, %struct.stat* %42, i32 0, i32 2
%44 = load i32, i32* %43
%45 = load %struct.passwd*, %struct.passwd** %9
%46 = getelementptr inbounds %struct.passwd, %struct.passwd* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %38, i32 %41, i32 %44, i32 %47)
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.passwd = type { i32 }
@.str = [5 x i8] c"Stat\00"
@.str.1 = [9 x i8] c"Getpwuid\00"
@.str.2 = [14 x i8] c"Getpwuid fake\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 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @stat(i8* %6, %struct.stat* %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @erreur_grave(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call %struct.passwd* @getpwuid(i32 %13)
%15 = icmp eq %struct.passwd* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @erreur_grave(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = tail call %struct.passwd* @getpwuid(i32 1000)
%20 = icmp eq %struct.passwd* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @erreur_grave(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** %5
%25 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %24, i32 %26, i32 %28, i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
%33 = tail call i32 @exit(i32 %32)
unreachable
}