#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 /*<<< orphan*/ getfname(char *, char const *);
struct passwd *getpwuid(int /*<<< orphan*/);
int stat(char *, struct stat *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int getowner(const char *tty, char *username) {
  char fname[22];
  struct stat st;
  struct passwd *pw;
  getfname(fname, tty);
  if (stat(fname, &st) == -1)
    return 0;
  if (pw = getpwuid(st.st_uid)) {
    strncpy(username, pw->pw_name, 15);
    username[15] = '\0';
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getowner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <getfname@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    117f <getowner+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11c4 <getowner+0x84>
mov    -0x38(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     11bd <getowner+0x7d>
mov    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    $0xf,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0xf(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c4 <getowner+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getowner>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <getfname@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1060 <stat@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     1193 <getowner+0x53>
mov    0x8(%rsp),%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1193 <getowner+0x53>
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0xf,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.passwd = type { i32 }
define i32 @getowner(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [22 x i8]
%7 = alloca %struct.stat
%8 = alloca %struct.passwd*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @getfname(i8* %9, i8* %10)
%12 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%13 = call i32 @stat(i8* %12, %struct.stat* %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 0, i32* %3
br label %30
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call %struct.passwd* @getpwuid(i32 %18)
store %struct.passwd* %19, %struct.passwd** %8
%20 = icmp ne %struct.passwd* %19, null
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load %struct.passwd*, %struct.passwd** %8
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @strncpy(i8* %22, i32 %25, i32 15)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 15
store i8 0, i8* %28
store i32 1, i32* %3
br label %30
29: ; preds = %16
store i32 0, i32* %3
br label %30
30: ; preds = %29, %21, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.passwd = type { i32 }
define i32 @getowner(i8* %0, i8* %1) {
%3 = alloca [22 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [22 x i8], [22 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @getfname(i8* %5, i8* %0)
%8 = call i32 @stat(i8* %5, %struct.stat* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call %struct.passwd* @getpwuid(i32 %12)
%14 = icmp eq %struct.passwd* %13, null
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @strncpy(i8* %1, i32 %17, i32 15)
%19 = getelementptr inbounds i8, i8* %1, i64 15
store i8 0, i8* %19
br label %20
20: ; preds = %10, %2, %15
%21 = phi i32 [ 1, %15 ], [ 0, %2 ], [ 0, %10 ]
ret i32 %21
}