#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 */
struct stat {
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int lchown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  int err, nerr;
  struct stat st;
  nerr = 0;
  while (*++argv) {
    err = lstat(*argv, &st);
    if (!err && S_ISLNK(st.st_mode))
      err = lchown(*argv, st.st_uid, st.st_gid);
    if (!err)
      continue;
    perror(*argv);
    nerr++;
  }
  return nerr;
}


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)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
je     11e4 <main+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11bb <main+0x7b>
mov    -0x20(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     11bb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1050 <lchown@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ca <main+0x8a>
jmp    115d <main+0x1d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <main+0x1d>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
xor    %r14d,%r14d
mov    %rsp,%rbx
add    $0x8,%rbp
mov    %rbp,%rcx
jmp    1178 <main+0x38>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rdi
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
call   1050 <lchown@plt>
lea    0x8(%rbp),%rcx
test   %eax,%eax
jne    11a1 <main+0x61>
mov    (%rcx),%rdi
test   %rdi,%rdi
je     11b0 <main+0x70>
mov    %rcx,%rbp
mov    %rbx,%rsi
call   1040 <lstat@plt>
test   %eax,%eax
jne    11a1 <main+0x61>
mov    0x8(%rsp),%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
jne    1160 <main+0x20>
xor    %eax,%eax
jmp    1170 <main+0x30>
mov    0x0(%rbp),%rdi
call   1060 <perror@plt>
add    $0x1,%r14d
jmp    1151 <main+0x11>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %37, %36, %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i32 1
store i8** %11, i8*** %5
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %43
14: ; preds = %9
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i32 @lstat(i8* %16, %struct.stat* %8)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %33, label %20
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 2
%22 = load i32, i32* %21
%23 = call i64 @S_ISLNK(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @lchown(i8* %27, i32 %29, i32 %31)
store i32 %32, i32* %6
br label %33
33: ; preds = %25, %20, %14
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
br label %9
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = call i32 @perror(i8* %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %9
43: ; preds = %9
%44 = load i32, i32* %7
ret i32 %44
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%6 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %8
8: ; preds = %31, %2
%9 = phi i8** [ %13, %31 ], [ %1, %2 ]
%10 = phi i32 [ %34, %31 ], [ 0, %2 ]
br label %11
11: ; preds = %8, %28
%12 = phi i8** [ %13, %28 ], [ %9, %8 ]
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %35, label %16
16: ; preds = %11
%17 = call i32 @lstat(i8* %14, %struct.stat* %3)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i32, i32* %5
%21 = tail call i64 @S_ISLNK(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i8*, i8** %13
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = tail call i32 @lchown(i8* %24, i32 %25, i32 %26)
br label %28
28: ; preds = %23, %19
%29 = phi i32 [ %27, %23 ], [ 0, %19 ]
%30 = icmp eq i32 %29, 0
br i1 %30, label %11, label %31
31: ; preds = %16, %28
%32 = load i8*, i8** %13
%33 = tail call i32 @perror(i8* %32)
%34 = add nuw nsw i32 %10, 1
br label %8
35: ; preds = %11
ret i32 %10
}