#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*/ uid_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ _chown_gid(char *);
int /*<<< orphan*/ _chown_uid(char *);
int _chown_owner(char *owner, uid_t *uid, gid_t *gid) {
  int i;
  for (i = 0; owner[i] != 0; i++)
    if (owner[i] == ':') {
      owner[i++] = '\0';
      break;
    }
  if ((*uid = _chown_uid(owner)) == (uid_t)-1)
    return 1;
  if (owner[i] != '\0' && (*gid = _chown_gid(&owner[i])) == (gid_t)-1)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<_chown_owner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1193 <_chown_owner+0x73>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1180 <_chown_owner+0x60>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1193 <_chown_owner+0x73>
jmp    1185 <_chown_owner+0x65>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113b <_chown_owner+0x1b>
mov    -0x10(%rbp),%rdi
call   1040 <_chown_uid@plt>
mov    -0x18(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11b7 <_chown_owner+0x97>
movl   $0x1,-0x4(%rbp)
jmp    11fe <_chown_owner+0xde>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11f7 <_chown_owner+0xd7>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
call   1030 <_chown_gid@plt>
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11f7 <_chown_owner+0xd7>
movl   $0x1,-0x4(%rbp)
jmp    11fe <_chown_owner+0xde>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_chown_owner>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx,%rbp,1),%eax
test   %al,%al
je     115c <_chown_owner+0x3c>
cmp    $0x3a,%al
je     1152 <_chown_owner+0x32>
add    $0x1,%rbp
jmp    1140 <_chown_owner+0x20>
mov    %ebp,%eax
add    $0x1,%rbp
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1040 <_chown_uid@plt>
mov    %eax,(%r15)
mov    $0x1,%r15d
cmp    $0xffffffff,%eax
je     1191 <_chown_owner+0x71>
movslq %ebp,%rax
cmpb   $0x0,(%rbx,%rax,1)
je     118e <_chown_owner+0x6e>
add    %rax,%rbx
mov    %rbx,%rdi
call   1030 <_chown_gid@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     1191 <_chown_owner+0x71>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @_chown_owner(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
br label %4
4: ; preds = %12, %3
%5 = phi i64 [ %13, %12 ], [ 0, %3 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %12 [
i8 0, label %14
i8 58, label %8
]
8: ; preds = %4
%9 = and i64 %5, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = add i64 %5, 1
store i8 0, i8* %10
br label %14
12: ; preds = %4
%13 = add nuw i64 %5, 1
br label %4
14: ; preds = %4, %8
%15 = phi i64 [ %11, %8 ], [ %5, %4 ]
%16 = tail call i32 @_chown_uid(i8* %0)
store i32 %16, i32* %1
%17 = icmp eq i32 %16, -1
br i1 %17, label %28, label %18
18: ; preds = %14
%19 = shl i64 %15, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = tail call i32 @_chown_gid(i8* %21)
store i32 %25, i32* %2
%26 = icmp eq i32 %25, -1
br i1 %26, label %28, label %27
27: ; preds = %24, %18
br label %28
28: ; preds = %24, %14, %27
%29 = phi i32 [ 0, %27 ], [ 1, %14 ], [ 1, %24 ]
ret i32 %29
}