#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 spwd {
  int /*<<< orphan*/ sp_pwdp;
};

/* Variables and functions */
int ENOENT;
struct spwd *spwd_find(char *, char const *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, size_t);
int cmd_smac_adm_user_get(const char *name, char *buf, size_t buflen) {
  struct spwd *spwd;
  spwd = spwd_find("/smac_users", name);
  if (NULL == spwd) {
    return -ENOENT;
  }
  strncpy(buf, spwd->sp_pwdp, buflen);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_smac_adm_user_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec1(%rip),%rdi
call   1030 <spwd_find@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1167 <cmd_smac_adm_user_get+0x47>
xor    %eax,%eax
mov    0x2e7b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <cmd_smac_adm_user_get+0x61>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1040 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_smac_adm_user_get>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xecc(%rip),%rdi
call   1030 <spwd_find@plt>
test   %rax,%rax
je     114f <cmd_smac_adm_user_get+0x2f>
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <strncpy@plt>
xor    %eax,%eax
jmp    115a <cmd_smac_adm_user_get+0x3a>
mov    0x2e82(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.spwd = type { i32 }
@.str = [12 x i8] c"/smac_users\00"
@ENOENT = global i32 0
define i32 @cmd_smac_adm_user_get(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.spwd*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = call %struct.spwd* @spwd_find(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %9)
store %struct.spwd* %10, %struct.spwd** %8
%11 = load %struct.spwd*, %struct.spwd** %8
%12 = icmp eq %struct.spwd* null, %11
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i32, i32* @ENOENT
%15 = sub nsw i32 0, %14
store i32 %15, i32* %4
br label %23
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = load %struct.spwd*, %struct.spwd** %8
%19 = getelementptr inbounds %struct.spwd, %struct.spwd* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i64, i64* %7
%22 = call i32 @strncpy(i8* %17, i32 %20, i64 %21)
store i32 0, i32* %4
br label %23
23: ; preds = %16, %13
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
@.str = [12 x i8] c"/smac_users\00"
@ENOENT = global i32 0
define i32 @cmd_smac_adm_user_get(i8* %0, i8* %1, i64 %2) {
%4 = tail call %struct.spwd* @spwd_find(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp eq %struct.spwd* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @ENOENT
%8 = sub nsw i32 0, %7
br label %13
9: ; preds = %3
%10 = getelementptr inbounds %struct.spwd, %struct.spwd* %4, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @strncpy(i8* %1, i32 %11, i64 %2)
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ %8, %6 ], [ 0, %9 ]
ret i32 %14
}