#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 {
  scalar_t__ st_uid;
};
struct passwd {
  scalar_t__ pw_uid;
};

/* Variables and functions */
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char const *const);
struct passwd *getpwnam(char const *const);
struct passwd *getpwuid(int);
int strtol(char const *const, char **, int);
int check_user(struct stat fd_in, const char *const *parms, int parm_pos) {
  struct passwd *username = NULL;
  char *endptr = NULL;
  int char2int = 0;
  username = getpwnam(parms[parm_pos + 1]);
  if (username == NULL) {
    char2int = strtol(parms[parm_pos + 1], &endptr, 10);
    if (char2int == 0) {
      error(0, 0, "%s is not the name of a known user", parms[parm_pos + 1]);
      return 0;
    }
    username = getpwuid(char2int);
    if (username == NULL) {
      error(0, 0, "%s is not the name of a known user", parms[parm_pos + 1]);
      return 0;
    }
  }
  if ((fd_in.st_uid) == (username->pw_uid))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<check_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <getpwnam@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <check_user+0xf1>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11e8 <check_user+0xa8>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
xor    %esi,%esi
lea    0xe2b(%rip),%rdx
mov    %esi,%edi
call   1060 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <check_user+0x115>
mov    -0x34(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    122c <check_user+0xec>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
xor    %esi,%esi
lea    0xde7(%rip),%rdx
mov    %esi,%edi
call   1060 <error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <check_user+0x115>
jmp    1231 <check_user+0xf1>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmp    (%rcx),%rax
jne    124e <check_user+0x10e>
movl   $0x1,-0x4(%rbp)
jmp    1255 <check_user+0x115>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_user>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
movslq %edx,%rbx
mov    0x8(%rsi,%rbx,8),%rdi
call   1040 <getpwnam@plt>
test   %rax,%rax
je     1174 <check_user+0x34>
xor    %ebx,%ebx
cmp    %r14,(%rax)
sete   %bl
jmp    11b1 <check_user+0x71>
add    $0x1,%rbx
mov    (%r15,%rbx,8),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %eax,%eax
je     119b <check_user+0x5b>
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
jne    116a <check_user+0x2a>
mov    (%r15,%rbx,8),%rcx
lea    0xe5a(%rip),%rdx
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <error@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
%struct.passwd = type { i64 }
@.str = [35 x i8] c"%s is not the name of a known user\00"
define i32 @check_user(i64 %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca i8**
%7 = alloca i32
%8 = alloca %struct.passwd*
%9 = alloca i8*
%10 = alloca i32
%11 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
store i64 %0, i64* %11
store i8** %1, i8*** %6
store i32 %2, i32* %7
store %struct.passwd* null, %struct.passwd** %8
store i8* null, i8** %9
store i32 0, i32* %10
%12 = load i8**, i8*** %6
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %12, i64 %15
%17 = load i8*, i8** %16
%18 = call %struct.passwd* @getpwnam(i8* %17)
store %struct.passwd* %18, %struct.passwd** %8
%19 = load %struct.passwd*, %struct.passwd** %8
%20 = icmp eq %struct.passwd* %19, null
br i1 %20, label %21, label %53
21: ; preds = %3
%22 = load i8**, i8*** %6
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %22, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strtol(i8* %27, i8** %9, i32 10)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %21
%32 = load i8**, i8*** %6
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %32, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @error(i32 0, i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %37)
store i32 0, i32* %4
br label %62
39: ; preds = %21
%40 = load i32, i32* %10
%41 = call %struct.passwd* @getpwuid(i32 %40)
store %struct.passwd* %41, %struct.passwd** %8
%42 = load %struct.passwd*, %struct.passwd** %8
%43 = icmp eq %struct.passwd* %42, null
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = load i8**, i8*** %6
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 @error(i32 0, i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %50)
store i32 0, i32* %4
br label %62
52: ; preds = %39
br label %53
53: ; preds = %52, %3
%54 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%55 = load i64, i64* %54
%56 = load %struct.passwd*, %struct.passwd** %8
%57 = getelementptr inbounds %struct.passwd, %struct.passwd* %56, i32 0, i32 0
%58 = load i64, i64* %57
%59 = icmp eq i64 %55, %58
br i1 %59, label %60, label %61
60: ; preds = %53
store i32 1, i32* %4
br label %62
61: ; preds = %53
store i32 0, i32* %4
br label %62
62: ; preds = %61, %60, %44, %31
%63 = load i32, i32* %4
ret i32 %63
}

LLVM IR (-O2):
%struct.passwd = type { i64 }
@.str = [35 x i8] c"%s is not the name of a known user\00"
define i32 @check_user(i64 %0, i8** nocapture %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = add nsw i32 %2, 1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call %struct.passwd* @getpwnam(i8* %9)
%11 = icmp eq %struct.passwd* %10, null
br i1 %11, label %12, label %25
12: ; preds = %3
%13 = load i8*, i8** %8
%14 = call i32 @strtol(i8* %13, i8** %4, i32 10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %8
%18 = tail call i32 @error(i32 0, i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %31
19: ; preds = %12
%20 = tail call %struct.passwd* @getpwuid(i32 %14)
%21 = icmp eq %struct.passwd* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %8
%24 = tail call i32 @error(i32 0, i32 0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %31
25: ; preds = %19, %3
%26 = phi %struct.passwd* [ %20, %19 ], [ %10, %3 ]
%27 = getelementptr inbounds %struct.passwd, %struct.passwd* %26, i64 0, i32 0
%28 = load i64, i64* %27
%29 = icmp eq i64 %28, %0
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %25, %22, %16
%32 = phi i32 [ 0, %16 ], [ 0, %22 ], [ %30, %25 ]
ret i32 %32
}