#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 cmd_smac_adm_user_append(char const *, char const *);
int cmd_smac_adm_user_replace(char const *, char const *);
struct spwd *spwd_find(char *, char const *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char const *);
int cmd_smac_adm_user_set(const char *name, const char *label) {
  struct spwd *spwd;
  spwd = spwd_find("/smac_users", name);
  if (!spwd) {
    return cmd_smac_adm_user_append(name, label);
  }
  if (!strcmp(spwd->sp_pwdp, label)) {
    return 0;
  }
  return cmd_smac_adm_user_replace(name, label);
}


x86 assembly (clang, -O0):
<cmd_smac_adm_user_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
call   1040 <spwd_find@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1184 <cmd_smac_adm_user_set+0x44>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <cmd_smac_adm_user_append@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <cmd_smac_adm_user_set+0x78>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a8 <cmd_smac_adm_user_set+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <cmd_smac_adm_user_set+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <cmd_smac_adm_user_replace@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_smac_adm_user_set>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rdi
mov    %rbx,%rsi
call   1040 <spwd_find@plt>
test   %rax,%rax
je     117e <cmd_smac_adm_user_set+0x3e>
mov    (%rax),%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <cmd_smac_adm_user_set+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <cmd_smac_adm_user_replace@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <cmd_smac_adm_user_append@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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