#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 */

/* Variables and functions */
int chown(char *, int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ log_error(char *, ...);
char *strdup(char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strtok(char *, char *);
int chown_delegation_token_files(char *delegation_token_files, int uid,
                                 int gid) {
  char *modifiable_delegation_token_files = strdup(delegation_token_files);
  if (modifiable_delegation_token_files == NULL) {
    log_error("Error: strdup returned NULL, system out of memory.");
    return -1;
  }
  char *delegation_token_file = strtok(modifiable_delegation_token_files, ",");
  while (delegation_token_file != NULL) {
    int chown_result = chown(delegation_token_file, uid, gid);
    if (chown_result != 0) {
      log_error(
          "Could not change ownership of file \"%s\" to UID %d and GID %d : %s",
          delegation_token_file, uid, gid, strerror(errno));
      free(modifiable_delegation_token_files);
      return -1;
    }
    delegation_token_file = strtok(NULL, ",");
  }
  free(modifiable_delegation_token_files);
  return 0;
}


x86 assembly (clang, -O0):
<chown_delegation_token_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <chown_delegation_token_files+0x44>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <log_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <chown_delegation_token_files+0xfa>
mov    -0x20(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124a <chown_delegation_token_files+0xea>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <chown@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1231 <chown_delegation_token_files+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <log_error@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <chown_delegation_token_files+0xfa>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf7(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11b8 <chown_delegation_token_files+0x58>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chown_delegation_token_files>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebx
call   1070 <strdup@plt>
test   %rax,%rax
je     11cf <chown_delegation_token_files+0x6f>
mov    %rax,%r14
lea    0xeb2(%rip),%rsi
mov    %rax,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c3 <chown_delegation_token_files+0x63>
mov    %rax,%rbp
lea    0xe9b(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1050 <chown@plt>
test   %eax,%eax
jne    11df <chown_delegation_token_files+0x7f>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11a0 <chown_delegation_token_files+0x40>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1213 <chown_delegation_token_files+0xb3>
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1040 <log_error@plt>
jmp    120e <chown_delegation_token_files+0xae>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe41(%rip),%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    %r15d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <log_error@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Error: strdup returned NULL, system out of memory.\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [66 x i8] c"Could not change ownership of file \22%s\22 to UID %d and GID %d : %s\00"
@errno = global i32 0
define i32 @chown_delegation_token_files(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %44
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = call i8* @strtok(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %9
br label %20
20: ; preds = %39, %17
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = load i8*, i8** %9
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = call i32 @chown(i8* %24, i32 %25, i32 %26)
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %23
%31 = load i8*, i8** %9
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32, i32 %33, i32 %35)
%37 = load i8*, i8** %8
%38 = call i32 @free(i8* %37)
store i32 -1, i32* %4
br label %44
39: ; preds = %23
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %9
br label %20
41: ; preds = %20
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
store i32 0, i32* %4
br label %44
44: ; preds = %41, %30, %15
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [51 x i8] c"Error: strdup returned NULL, system out of memory.\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [66 x i8] c"Could not change ownership of file \22%s\22 to UID %d and GID %d : %s\00"
@errno = global i32 0
define i32 @chown_delegation_token_files(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
br label %25
8: ; preds = %3
%9 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8, %20
%12 = phi i8* [ %21, %20 ], [ %9, %8 ]
%13 = tail call i32 @chown(i8* %12, i32 %1, i32 %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @errno
%17 = tail call i32 @strerror(i32 %16)
%18 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %1, i32 %2, i32 %17)
%19 = tail call i32 @free(i8* %4)
br label %25
20: ; preds = %11
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %11
23: ; preds = %20, %8
%24 = tail call i32 @free(i8* %4)
br label %25
25: ; preds = %15, %23, %6
%26 = phi i32 [ -1, %6 ], [ 0, %23 ], [ -1, %15 ]
ret i32 %26
}