#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 scalar_t__ uid_t;
struct passwd {
  scalar_t__ pw_uid;
  int /*<<< orphan*/ pw_name;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ atol(char *);
int chown(char *, scalar_t__, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct passwd *getpwent();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s OWNER FILE...\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  uid_t dst_uid;
  struct passwd *passwd_buf;
  while ((passwd_buf = getpwent()) != NULL) {
    if (passwd_buf->pw_uid == atol(argv[1]) ||
        strcmp(passwd_buf->pw_name, (char *)argv[0])) {
      dst_uid = passwd_buf->pw_uid;
      break;
    }
  }
  if (passwd_buf == NULL) {
    fprintf(stderr, "No such uid: %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  for (int i = 2; i < argc; ++i) {
    if (chown(argv[i], dst_uid, -1) == -1) {
      fprintf(stderr, "Failed to chown\n");
      perror(argv[i]);
      exit(EXIT_FAILURE);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bc <main+0x4c>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11c1 <main+0x51>
mov    $0x0,%al
call   1050 <getpwent@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1230 <main+0xc0>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     121b <main+0xab>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     122b <main+0xbb>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1230 <main+0xc0>
jmp    11c1 <main+0x51>
cmpq   $0x0,-0x20(%rbp)
jne    1268 <main+0xf8>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e7 <main+0x177>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <chown@plt>
cmp    $0xffffffff,%eax
jne    12d4 <main+0x164>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    12d9 <main+0x169>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126f <main+0xff>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x3,%edi
jl     125e <main+0xee>
mov    %edi,%r14d
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getpwent@plt>
test   %rax,%rax
je     1213 <main+0xa3>
mov    %rax,%rbx
mov    (%rax),%rbp
mov    0x8(%r15),%rdi
call   1070 <atol@plt>
cmp    %rax,%rbp
je     11c3 <main+0x53>
mov    0x8(%rbx),%edi
mov    (%r15),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1190 <main+0x20>
mov    (%rbx),%rbp
cmp    $0x3,%r14d
jl     11ff <main+0x8f>
mov    %r14d,%r14d
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %rbp,%rsi
mov    $0xffffffff,%edx
call   1060 <chown@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0xc0>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11e0 <main+0x70>
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xdf2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1250 <main+0xe0>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r15,%rbx,8),%rdi
call   1080 <perror@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xd8f(%rip),%rsi
jmp    1227 <main+0xb7>

LLVM IR (-O0):
%struct.passwd = type { i64, i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s OWNER FILE...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"No such uid: %s\0A\00"
@.str.2 = [17 x i8] c"Failed to chown\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca %struct.passwd*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
br label %20
20: ; preds = %45, %19
%21 = call %struct.passwd* (...) @getpwent()
store %struct.passwd* %21, %struct.passwd** %7
%22 = icmp ne %struct.passwd* %21, null
br i1 %22, label %23, label %46
23: ; preds = %20
%24 = load %struct.passwd*, %struct.passwd** %7
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @atol(i8* %29)
%31 = icmp eq i64 %26, %30
br i1 %31, label %41, label %32
32: ; preds = %23
%33 = load %struct.passwd*, %struct.passwd** %7
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i32 %35, i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %32, %23
%42 = load %struct.passwd*, %struct.passwd** %7
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 0
%44 = load i64, i64* %43
store i64 %44, i64* %6
br label %46
45: ; preds = %32
br label %20
46: ; preds = %41, %20
%47 = load %struct.passwd*, %struct.passwd** %7
%48 = icmp eq %struct.passwd* %47, null
br i1 %48, label %49, label %57
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %46
store i32 2, i32* %8
br label %58
58: ; preds = %83, %57
%59 = load i32, i32* %8
%60 = load i32, i32* %4
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %86
62: ; preds = %58
%63 = load i8**, i8*** %5
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %63, i64 %65
%67 = load i8*, i8** %66
%68 = load i64, i64* %6
%69 = call i32 @chown(i8* %67, i64 %68, i32 -1)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %82
71: ; preds = %62
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%74 = load i8**, i8*** %5
%75 = load i32, i32* %8
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8*, i8** %74, i64 %76
%78 = load i8*, i8** %77
%79 = call i32 @perror(i8* %78)
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %62
br label %83
83: ; preds = %82
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
br label %58
86: ; preds = %58
%87 = load i32, i32* @EXIT_SUCCESS
ret i32 %87
}

LLVM IR (-O2):
%struct.passwd = type { i64, i32 }
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s OWNER FILE...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"No such uid: %s\0A\00"
@.str.2 = [17 x i8] c"Failed to chown\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
br label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4, %21
%13 = tail call %struct.passwd* (...) @getpwent()
%14 = icmp eq %struct.passwd* %13, null
br i1 %14, label %35, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 0
%17 = load i64, i64* %16
%18 = load i8*, i8** %5
%19 = tail call i64 @atol(i8* %18)
%20 = icmp eq i64 %17, %19
br i1 %20, label %30, label %21
21: ; preds = %15
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 1
%23 = load i32, i32* %22
%24 = load i8*, i8** %1
%25 = tail call i64 @strcmp(i32 %23, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %21
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %13, i64 0, i32 0
%29 = load i64, i64* %28
br label %30
30: ; preds = %15, %27
%31 = phi i64 [ %29, %27 ], [ %17, %15 ]
%32 = icmp sgt i32 %0, 2
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = zext i32 %0 to i64
br label %43
35: ; preds = %12
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %5
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %58, %30
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
43: ; preds = %33, %58
%44 = phi i64 [ 2, %33 ], [ %59, %58 ]
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = tail call i32 @chown(i8* %46, i64 %31, i32 -1)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %58
49: ; preds = %43
%50 = and i64 %44, 4294967295
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%54 = load i8*, i8** %51
%55 = tail call i32 @perror(i8* %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = tail call i32 @exit(i32 %56)
unreachable
58: ; preds = %43
%59 = add nuw nsw i64 %44, 1
%60 = icmp eq i64 %59, %34
br i1 %60, label %41, label %43
}