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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(struct spwd *, int /*<<< orphan*/, int);
int putspent(struct spwd *, int /*<<< orphan*/ *);
int cmd_smac_adm_user_append(const char *name, const char *label) {
  FILE *su;
  struct spwd spwd;
  int ret;
  su = fopen("/smac_users", "a");
  if (!su) {
    return -errno;
  }
  memset(&spwd, 0, sizeof(spwd));
  spwd.sp_namp = (char *)name;
  spwd.sp_pwdp = (char *)label;
  ret = putspent(&spwd, su);
  fclose(su);
  return ret;
}


x86 assembly (clang, -O0):
<cmd_smac_adm_user_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1185 <cmd_smac_adm_user_append+0x45>
xor    %eax,%eax
mov    0x2e65(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c4 <cmd_smac_adm_user_append+0x84>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1030 <putspent@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_smac_adm_user_append>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xea9(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <cmd_smac_adm_user_append+0x60>
mov    %rax,%rbx
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <putspent@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11ab <cmd_smac_adm_user_append+0x6b>
mov    0x2e39(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.spwd = type { i8*, i8* }
@.str = [12 x i8] c"/smac_users\00"
@.str.1 = [2 x i8] c"a\00"
@errno = global i32 0
define i32 @cmd_smac_adm_user_append(i8* %0, i8* %1) {
%3 = alloca %struct.spwd
%4 = bitcast %struct.spwd* %3 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %16
10: ; preds = %2
%11 = call i32 @memset(%struct.spwd* %3, i32 0, i32 16)
%12 = getelementptr inbounds %struct.spwd, %struct.spwd* %3, i64 0, i32 0
store i8* %0, i8** %12
%13 = getelementptr inbounds %struct.spwd, %struct.spwd* %3, i64 0, i32 1
store i8* %1, i8** %13
%14 = call i32 @putspent(%struct.spwd* %3, i32* %5)
%15 = call i32 @fclose(i32* %5)
br label %16
16: ; preds = %10, %7
%17 = phi i32 [ %14, %10 ], [ %9, %7 ]
ret i32 %17
}