#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 group {
  char *gr_name;
  char *gr_passwd;
  int /*<<< orphan*/ gr_mem;
  scalar_t__ gr_gid;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
scalar_t__ atoi(char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ strsplit(char *, char);
int exfiles_copy_group_from_gr_entry(struct group *grbuf, char **gr_entry) {
  int tmplen = 0;
  tmplen = strlen(gr_entry[0]);
  strncpy(grbuf->gr_name, gr_entry[0], tmplen + 1);
  if (strlen(grbuf->gr_name) != tmplen)
    return -1;
  tmplen = strlen(gr_entry[1]);
  strncpy(grbuf->gr_passwd, gr_entry[1], tmplen + 1);
  if (strlen(grbuf->gr_passwd) != tmplen)
    return -1;
  grbuf->gr_gid = (gid_t)atoi(gr_entry[2]);
  grbuf->gr_mem = strsplit(gr_entry[3], ',');
  return 0;
}


x86 assembly (clang, -O0):
<exfiles_copy_group_from_gr_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    -0x1c(%rbp),%eax
je     11a0 <exfiles_copy_group_from_gr_entry+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <exfiles_copy_group_from_gr_entry+0xe7>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
cmp    -0x1c(%rbp),%eax
je     11ed <exfiles_copy_group_from_gr_entry+0xad>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <exfiles_copy_group_from_gr_entry+0xe7>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rdi
mov    $0x2c,%esi
call   1060 <strsplit@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exfiles_copy_group_from_gr_entry>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    (%r14),%rdi
mov    (%rbx),%rsi
lea    0x1(%rbp),%edx
call   1030 <strncpy@plt>
mov    (%r14),%rdi
call   1040 <strlen@plt>
mov    $0xffffffff,%r15d
cmp    %ebp,%eax
jne    11c1 <exfiles_copy_group_from_gr_entry+0x81>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x8(%r14),%rdi
mov    0x8(%rbx),%rsi
lea    0x1(%rbp),%edx
call   1030 <strncpy@plt>
mov    0x8(%r14),%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jne    11c1 <exfiles_copy_group_from_gr_entry+0x81>
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %rax,0x18(%r14)
mov    0x18(%rbx),%rdi
mov    $0x2c,%esi
call   1060 <strsplit@plt>
mov    %eax,0x10(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8*, i8*, i32, i64 }
define i32 @exfiles_copy_group_from_gr_entry(%struct.group* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.group*
%5 = alloca i8**
%6 = alloca i32
store %struct.group* %0, %struct.group** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load %struct.group*, %struct.group** %4
%12 = getelementptr inbounds %struct.group, %struct.group* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = call i32 @strncpy(i8* %13, i8* %16, i32 %18)
%20 = load %struct.group*, %struct.group** %4
%21 = getelementptr inbounds %struct.group, %struct.group* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
%24 = load i32, i32* %6
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %2
store i32 -1, i32* %3
br label %61
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %6
%32 = load %struct.group*, %struct.group** %4
%33 = getelementptr inbounds %struct.group, %struct.group* %32, i32 0, i32 1
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
%40 = call i32 @strncpy(i8* %34, i8* %37, i32 %39)
%41 = load %struct.group*, %struct.group** %4
%42 = getelementptr inbounds %struct.group, %struct.group* %41, i32 0, i32 1
%43 = load i8*, i8** %42
%44 = call i32 @strlen(i8* %43)
%45 = load i32, i32* %6
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %27
store i32 -1, i32* %3
br label %61
48: ; preds = %27
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i64 @atoi(i8* %51)
%53 = load %struct.group*, %struct.group** %4
%54 = getelementptr inbounds %struct.group, %struct.group* %53, i32 0, i32 3
store i64 %52, i64* %54
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 3
%57 = load i8*, i8** %56
%58 = call i32 @strsplit(i8* %57, i8 signext 44)
%59 = load %struct.group*, %struct.group** %4
%60 = getelementptr inbounds %struct.group, %struct.group* %59, i32 0, i32 2
store i32 %58, i32* %60
store i32 0, i32* %3
br label %61
61: ; preds = %48, %47, %26
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
%struct.group = type { i8*, i8*, i32, i64 }
define i32 @exfiles_copy_group_from_gr_entry(%struct.group* nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @strlen(i8* %3)
%5 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 0
%6 = load i8*, i8** %5
%7 = load i8*, i8** %1
%8 = add nsw i32 %4, 1
%9 = tail call i32 @strncpy(i8* %6, i8* %7, i32 %8)
%10 = load i8*, i8** %5
%11 = tail call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, %4
br i1 %12, label %13, label %34
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strlen(i8* %15)
%17 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 1
%18 = load i8*, i8** %17
%19 = load i8*, i8** %14
%20 = add nsw i32 %16, 1
%21 = tail call i32 @strncpy(i8* %18, i8* %19, i32 %20)
%22 = load i8*, i8** %17
%23 = tail call i32 @strlen(i8* %22)
%24 = icmp eq i32 %23, %16
br i1 %24, label %25, label %34
25: ; preds = %13
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i64 @atoi(i8* %27)
%29 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 3
store i64 %28, i64* %29
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = tail call i32 @strsplit(i8* %31, i8 signext 44)
%33 = getelementptr inbounds %struct.group, %struct.group* %0, i64 0, i32 2
store i32 %32, i32* %33
br label %34
34: ; preds = %13, %2, %25
%35 = phi i32 [ 0, %25 ], [ -1, %2 ], [ -1, %13 ]
ret i32 %35
}