#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;
  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)
cmpl   $0x3,-0x8(%rbp)
jge    1163 <main+0x33>
xor    %eax,%eax
mov    0x2e7f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <main+0x10b>
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    11b4 <main+0x84>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2e2e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <main+0x10b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1220 <main+0xf0>
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    1219 <main+0xe9>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    0x2dc9(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <main+0x10b>
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    11db <main+0xab>
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     11ad <main+0x7d>
mov    %rax,%r15
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     11bf <main+0x8f>
add    $0x10,%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
mov    $0x1,%ecx
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <chown_do@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
jmp    11cf <main+0x9f>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dfd(%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
%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 %38
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 %38
22: ; preds = %10
%23 = load i8, i8* %14
%24 = icmp eq i8 %23, 58
tail call void @llvm.assume(i1 %24)
%25 = bitcast i8** %4 to i8*
%26 = getelementptr inbounds i8, i8* %14, i64 1
%27 = call i8* @strtol(i8* %26, i8** %4, i32 0)
%28 = load i8*, i8** %4
%29 = icmp eq i8* %26, %28
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EINVAL
%34 = sub nsw i32 0, %33
br label %38
35: ; preds = %22
%36 = getelementptr inbounds i8*, i8** %1, i64 2
%37 = tail call i32 @chown_do(i8** %36, i8* %13, i8* %27, i32 1)
br label %38
38: ; preds = %30, %35, %17, %7
%39 = phi i32 [ %9, %7 ], [ %21, %17 ], [ %37, %35 ], [ %34, %30 ]
ret i32 %39
}