#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*/ buf;

/* Variables and functions */
int cm_append_entry(char *, size_t, char *);
size_t snprintf(char *, int, char *, char *, char *);
int addgshadow(char *group, char *passwd) {
  int i;
  static char buf[512];
  size_t n;
  if (passwd[0] == '\0') {
    passwd = "!";
  }
  n = snprintf(buf, sizeof(buf), "%s:%s::\n", group, passwd);
  if ((i = cm_append_entry(buf, n, "/etc/gshadow")) != 0) {
    return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<addgshadow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114b <addgshadow+0x2b>
lea    0xeb9(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0x2ee6(%rip),%rdi
mov    $0x200,%esi
lea    0xe9c(%rip),%rdx
call   1030 <snprintf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0x2ec6(%rip),%rdi
lea    0xe8a(%rip),%rdx
call   1040 <cm_append_entry@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     119d <addgshadow+0x7d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <addgshadow+0x84>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addgshadow>:
push   %rbx
cmpb   $0x0,(%rsi)
mov    %rdi,%rcx
lea    0xed2(%rip),%r8
cmovne %rsi,%r8
lea    0x2f07(%rip),%rbx
lea    0xec2(%rip),%rdx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1030 <snprintf@plt>
lea    0xeb7(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
jmp    1040 <cm_append_entry@plt>

LLVM IR (-O0):
@addgshadow.buf = internal global [512 x i8] zeroinitializer
@.str = [2 x i8] c"!\00"
@.str.1 = [9 x i8] c"%s:%s::\0A\00"
@.str.2 = [13 x i8] c"/etc/gshadow\00"
define i32 @addgshadow(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5
br label %14
14: ; preds = %13, %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i64 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @addgshadow.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = call i32 @cm_append_entry(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @addgshadow.buf, i64 0, i64 0), i64 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 %19, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %24
23: ; preds = %14
store i32 0, i32* %3
br label %24
24: ; preds = %23, %21
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@addgshadow.buf = internal global [512 x i8] zeroinitializer
@.str = [2 x i8] c"!\00"
@.str.1 = [9 x i8] c"%s:%s::\0A\00"
@.str.2 = [13 x i8] c"/etc/gshadow\00"
define i32 @addgshadow(i8* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1
%6 = tail call i64 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @addgshadow.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %5)
%7 = tail call i32 @cm_append_entry(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @addgshadow.buf, i64 0, i64 0), i64 %6, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret i32 %7
}