#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 void *uid_t;
typedef void *gid_t;

/* Variables and functions */
int EINVAL;
int chown_do(char **, void *, void *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void *strtol(char *, char **, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  uid_t owner_id;
  bool is_group_set;
  gid_t group_id = 0;
  char *delim;
  if (argc < 3) {
    return -EINVAL;
  }
  owner_id = strtol(argv[1], &delim, 0);
  if (delim == argv[1]) {
    fprintf(stderr, "first argument should be owner id\n");
    return -EINVAL;
  }
  if (*delim == ':') {
    char *end;
    delim += 1;
    group_id = strtol(delim, &end, 0);
    if (delim == end) {
      fprintf(stderr, "after semicolon should be group id\n");
      return -EINVAL;
    }
    is_group_set = true;
  }
  return chown_do(argv + 2, owner_id, group_id, is_group_set);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116b <main+0x3b>
xor    %eax,%eax
mov    0x2e77(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <main+0x113>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    11bc <main+0x8c>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2e26(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <main+0x113>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1228 <main+0xf8>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1221 <main+0xf1>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2dc1(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1243 <main+0x113>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <chown_do@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jg     114d <main+0x1d>
mov    0x2e92(%rip),%rax
xor    %ebp,%ebp
jmp    11e4 <main+0xb4>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0x10(%rsp),%rsi
xor    %ebp,%ebp
xor    %edx,%edx
call   1050 <strtol@plt>
mov    0x10(%rsp),%rbx
cmp    0x8(%r14),%rbx
je     1196 <main+0x66>
mov    %rax,%r15
cmpb   $0x3a,(%rbx)
jne    11a8 <main+0x78>
add    $0x1,%rbx
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    0x8(%rsp),%rbx
je     11c8 <main+0x98>
mov    %rax,%rdx
jmp    11aa <main+0x7a>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
jmp    11d8 <main+0xa8>
xor    %edx,%edx
add    $0x10,%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <chown_do@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df4(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"first argument should be owner id\0A\00"
@.str.1 = [36 x i8] c"after semicolon should be group id\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
store i32 %15, i32* %3
br label %57
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i8* @strtol(i8* %19, i8** %9, i32 0)
store i8* %20, i8** %6
%21 = load i8*, i8** %9
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %21, %24
br i1 %25, label %26, label %31
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @EINVAL
%30 = sub nsw i32 0, %29
store i32 %30, i32* %3
br label %57
31: ; preds = %16
%32 = load i8*, i8** %9
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 58
br i1 %35, label %36, label %50
36: ; preds = %31
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = call i8* @strtol(i8* %39, i8** %10, i32 0)
store i8* %40, i8** %8
%41 = load i8*, i8** %9
%42 = load i8*, i8** %10
%43 = icmp eq i8* %41, %42
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32, i32* @EINVAL
%48 = sub nsw i32 0, %47
store i32 %48, i32* %3
br label %57
49: ; preds = %36
store i32 1, i32* %7
br label %50
50: ; preds = %49, %31
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %6
%54 = load i8*, i8** %8
%55 = load i32, i32* %7
%56 = call i32 @chown_do(i8** %52, i8* %53, i8* %54, i32 %55)
store i32 %56, i32* %3
br label %57
57: ; preds = %50, %44, %26, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"first argument should be owner id\0A\00"
@.str.1 = [36 x i8] c"after semicolon should be group id\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @EINVAL
%9 = sub nsw i32 0, %8
br label %41
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i8* @strtol(i8* %12, i8** %3, i32 0)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %11
%16 = icmp eq i8* %14, %15
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EINVAL
%21 = sub nsw i32 0, %20
br label %41
22: ; preds = %10
%23 = load i8, i8* %14
%24 = icmp eq i8 %23, 58
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = bitcast i8** %4 to i8*
%27 = getelementptr inbounds i8, i8* %14, i64 1
%28 = call i8* @strtol(i8* %27, i8** %4, i32 0)
%29 = load i8*, i8** %4
%30 = icmp eq i8* %27, %29
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EINVAL
%35 = sub nsw i32 0, %34
br label %41
36: ; preds = %25
br label %37
37: ; preds = %36, %22
%38 = phi i8* [ %28, %36 ], [ null, %22 ]
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = tail call i32 @chown_do(i8** %39, i8* %13, i8* %38, i32 1)
br label %41
41: ; preds = %31, %37, %17, %7
%42 = phi i32 [ %9, %7 ], [ %21, %17 ], [ %40, %37 ], [ %35, %31 ]
ret i32 %42
}