#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 /*<<< orphan*/ uid_t;
struct passwd {
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_passwd;
};

/* Variables and functions */
struct passwd *getpwnam(char const *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
int audit_name_to_uid(const char *name, uid_t *uid) {
  struct passwd *pw;
  pw = getpwnam(name);
  if (pw == NULL)
    return 1;
  memset(pw->pw_passwd, ' ', strlen(pw->pw_passwd));
  *uid = pw->pw_uid;
  return 0;
}


x86 assembly (clang, -O0):
<audit_name_to_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1164 <audit_name_to_uid+0x34>
movl   $0x1,-0x4(%rbp)
jmp    119c <audit_name_to_uid+0x6c>
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<audit_name_to_uid>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
call   1050 <getpwnam@plt>
test   %rax,%rax
je     1165 <audit_name_to_uid+0x35>
mov    %rax,%rbx
mov    0x4(%rax),%ebp
mov    %ebp,%edi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    $0x20,%esi
mov    %eax,%edx
call   1040 <memset@plt>
mov    (%rbx),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    116a <audit_name_to_uid+0x3a>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
define i32 @audit_name_to_uid(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.passwd*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = call %struct.passwd* @getpwnam(i8* %7)
store %struct.passwd* %8, %struct.passwd** %6
%9 = load %struct.passwd*, %struct.passwd** %6
%10 = icmp eq %struct.passwd* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %25
12: ; preds = %2
%13 = load %struct.passwd*, %struct.passwd** %6
%14 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.passwd*, %struct.passwd** %6
%17 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @strlen(i32 %18)
%20 = call i32 @memset(i32 %15, i8 signext 32, i32 %19)
%21 = load %struct.passwd*, %struct.passwd** %6
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32*, i32** %5
store i32 %23, i32* %24
store i32 0, i32* %3
br label %25
25: ; preds = %12, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
define i32 @audit_name_to_uid(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call %struct.passwd* @getpwnam(i8* %0)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 1
%7 = load i32, i32* %6
%8 = tail call i32 @strlen(i32 %7)
%9 = tail call i32 @memset(i32 %7, i8 signext 32, i32 %8)
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %1
br label %12
12: ; preds = %2, %5
%13 = phi i32 [ 0, %5 ], [ 1, %2 ]
ret i32 %13
}