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

/* Variables and functions */
int errno;
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, size_t);
int cm_get_owner(struct stat *s, char **owner) {
  size_t bs = 256;
  errno = 0;
  struct passwd *pw = getpwuid(s->st_uid);
  if (pw == NULL) {
    return -errno;
  }
  strncpy(*owner, pw->pw_name, bs);
  return 0;
}


x86 assembly (clang, -O0):
<cm_get_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x100,-0x20(%rbp)
mov    0x2ea1(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1172 <cm_get_owner+0x52>
xor    %eax,%eax
mov    0x2e78(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <cm_get_owner+0x6f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm_get_owner>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2eb2(%rip),%r14
movl   $0x0,(%r14)
mov    (%rdi),%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1154 <cm_get_owner+0x34>
mov    (%rbx),%rdi
mov    (%rax),%esi
mov    $0x100,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
jmp    1159 <cm_get_owner+0x39>
xor    %eax,%eax
sub    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.passwd = type { i32 }
@errno = global i32 0
define i32 @cm_get_owner(%struct.stat* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.stat*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca %struct.passwd*
store %struct.stat* %0, %struct.stat** %4
store i8** %1, i8*** %5
store i64 256, i64* %6
store i32 0, i32* @errno
%8 = load %struct.stat*, %struct.stat** %4
%9 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call %struct.passwd* @getpwuid(i32 %10)
store %struct.passwd* %11, %struct.passwd** %7
%12 = load %struct.passwd*, %struct.passwd** %7
%13 = icmp eq %struct.passwd* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = sub nsw i32 0, %15
store i32 %16, i32* %3
br label %25
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = load i8*, i8** %18
%20 = load %struct.passwd*, %struct.passwd** %7
%21 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i64, i64* %6
%24 = call i32 @strncpy(i8* %19, i32 %22, i64 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %17, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.passwd = type { i32 }
@errno = global i32 0
define i32 @cm_get_owner(%struct.stat* nocapture %0, i8** nocapture %1) {
store i32 0, i32* @errno
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call %struct.passwd* @getpwuid(i32 %4)
%6 = icmp eq %struct.passwd* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %15
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = getelementptr inbounds %struct.passwd, %struct.passwd* %5, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 @strncpy(i8* %11, i32 %13, i64 256)
br label %15
15: ; preds = %10, %7
%16 = phi i32 [ %9, %7 ], [ 0, %10 ]
ret i32 %16
}