#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 */
typedef int uid_t;
struct stat {
  int st_gid;
  int st_uid;
};
typedef int gid_t;

/* Variables and functions */
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int fileownership(char *str_path) {
  struct stat buf;
  if (lstat(str_path, &buf) < 0) {
    perror("stat() failed");
    return -1;
  }
  gid_t grpid = buf.st_gid;
  uid_t usrid = buf.st_uid;
  printf("%5d\t", grpid);
  printf("%5d\t", usrid);
  return 0;
}


x86 assembly (clang, -O0):
<fileownership>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    116b <fileownership+0x3b>
lea    0xea6(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <fileownership+0x6c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileownership>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     116b <fileownership+0x3b>
mov    (%rsp),%esi
mov    0x4(%rsp),%ebx
lea    0xebf(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe8e(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1163 <fileownership+0x33>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [14 x i8] c"stat() failed\00"
@.str.1 = [5 x i8] c"%5d\09\00"
define i32 @fileownership(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @lstat(i8* %7, %struct.stat* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %21
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %5
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 0, i32* %2
br label %21
21: ; preds = %12, %10
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [14 x i8] c"stat() failed\00"
@.str.1 = [5 x i8] c"%5d\09\00"
define i32 @fileownership(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
8: ; preds = %1
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%12 = load i32, i32* %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %15
15: ; preds = %8, %6
%16 = phi i32 [ -1, %6 ], [ 0, %8 ]
ret i32 %16
}