#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 st_uid;
  int st_gid;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int chown(char *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char *src, *desc;
  struct stat sb;
  if (argc == 3) {
    src = argv[1];
    desc = argv[2];
    if (stat(src, &sb) == -1) {
      perror("stat");
      exit(EXIT_FAILURE);
    }
    int uid = sb.st_uid;
    int gid = sb.st_gid;
    int r = chown(desc, uid, gid);
    if (r == 0) {
      printf("chown %s from %s success!\n", desc, src);
    } else {
      printf("chown %s from %s error!\n", desc, src);
    }
  } else {
    fprintf(stderr, "argv error!\n");
    exit(EXIT_FAILURE);
  }
  return 0;
}


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)
jne    1222 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c8 <main+0x68>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1060 <chown@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1209 <main+0xa9>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
jmp    121d <main+0xbd>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
jmp    1245 <main+0xe5>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11b9 <main+0x59>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rbx
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x70>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
call   1060 <chown@plt>
test   %eax,%eax
lea    0xe6c(%rip),%rax
lea    0xe80(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11dc <main+0x7c>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [5 x i8] c"stat\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"chown %s from %s success!\0A\00"
@.str.2 = [25 x i8] c"chown %s from %s error!\0A\00"
@stderr = global i32 0
@.str.3 = [13 x i8] c"argv error!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 3
br i1 %13, label %14, label %48
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = call i32 @stat(i8* %21, %struct.stat* %8)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
%29 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%30 = load i32, i32* %29
store i32 %30, i32* %9
%31 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%32 = load i32, i32* %31
store i32 %32, i32* %10
%33 = load i8*, i8** %7
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = call i32 @chown(i8* %33, i32 %34, i32 %35)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %28
%40 = load i8*, i8** %7
%41 = load i8*, i8** %6
%42 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %41)
br label %47
43: ; preds = %28
%44 = load i8*, i8** %7
%45 = load i8*, i8** %6
%46 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %45)
br label %47
47: ; preds = %43, %39
br label %53
48: ; preds = %2
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [5 x i8] c"stat\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"chown %s from %s success!\0A\00"
@.str.2 = [25 x i8] c"chown %s from %s error!\0A\00"
@stderr = global i32 0
@.str.3 = [13 x i8] c"argv error!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %26
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = call i32 @stat(i8* %8, %struct.stat* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%21 = load i32, i32* %20
%22 = tail call i32 @chown(i8* %10, i32 %19, i32 %21)
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0)
%25 = tail call i32 @printf(i8* %24, i8* %10, i8* %8)
ret i32 0
26: ; preds = %2
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
}