#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);
int addgroup(char *group, int gid, char *passwd) {
  int i;
  static char buf[512];
  size_t n;
  if (passwd[0] == '\0') {
    passwd = "x";
  }
  n = snprintf(buf, sizeof(buf), "%s:%s:%d:\n", group, passwd, gid);
  if ((i = cm_append_entry(buf, n, "/etc/group")) != 0) {
    return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<addgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114e <addgroup+0x2e>
lea    0xeb6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x14(%rbp),%r9d
lea    0x2edf(%rip),%rdi
mov    $0x200,%esi
lea    0xe95(%rip),%rdx
call   1030 <snprintf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0x2ebf(%rip),%rdi
lea    0xe85(%rip),%rdx
call   1040 <cm_append_entry@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     11a4 <addgroup+0x84>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <addgroup+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addgroup>:
push   %rbx
cmpb   $0x0,(%rdx)
mov    %esi,%r9d
mov    %rdi,%rcx
lea    0xecf(%rip),%r8
cmovne %rdx,%r8
lea    0x2f04(%rip),%rbx
lea    0xebf(%rip),%rdx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1030 <snprintf@plt>
lea    0xeb6(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rsi
pop    %rbx
jmp    1040 <cm_append_entry@plt>

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

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