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

/* Variables and functions */
int chown(char *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(void) {
  struct stat statbuf;
  if (stat("test.txt", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("before changing owner\n");
  printf("the owner of test.txt is : %d\n", (unsigned int)statbuf.st_uid);
  printf("the group of test.txt is : %d\n", (unsigned int)statbuf.st_gid);
  printf("\n");
  if (chown("test.txt", 0, -1) == -1) {
    perror("fail to change owner");
    exit(1);
  }
  if (stat("test.txt", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("after changing owner\n");
  printf("the owner of test.txt is : %d\n", (unsigned int)statbuf.st_uid);
  printf("the group of test.txt is : %d\n", (unsigned int)statbuf.st_gid);
  printf("\n");
  if (chown("test.txt", 100, -1) == -1) {
    perror("fail to change owner");
    exit(1);
  }
  if (stat("test.txt", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("nonexsit owner\n");
  printf("the owner of test.txt is : %d\n", (unsigned int)statbuf.st_uid);
  printf("the group of test.txt is : %d\n", (unsigned int)statbuf.st_gid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    118e <main+0x3e>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
cmp    $0xffffffff,%eax
jne    1204 <main+0xb4>
lea    0xe7c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xdf5(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1233 <main+0xe3>
lea    0xde5(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd82(%rip),%rdi
mov    $0x64,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
cmp    $0xffffffff,%eax
jne    12ac <main+0x15c>
lea    0xdd4(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xd4d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    12db <main+0x18b>
lea    0xd3d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xe85(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     12a0 <main+0x130>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe31(%rip),%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1070 <chown@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x139>
lea    0xe15(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     12a0 <main+0x130>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%esi
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdc1(%rip),%rdi
mov    $0x64,%esi
mov    $0xffffffff,%edx
call   1070 <chown@plt>
cmp    $0xffffffff,%eax
je     12a9 <main+0x139>
lea    0xda6(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     12a0 <main+0x130>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    0x10(%rsp),%esi
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xd62(%rip),%rdi
jmp    12b0 <main+0x140>
lea    0xdaa(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [19 x i8] c"fail to get status\00"
@.str.2 = [23 x i8] c"before changing owner\0A\00"
@.str.3 = [31 x i8] c"the owner of test.txt is : %d\0A\00"
@.str.4 = [31 x i8] c"the group of test.txt is : %d\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [21 x i8] c"fail to change owner\00"
@.str.7 = [22 x i8] c"after changing owner\0A\00"
@.str.8 = [16 x i8] c"nonexsit owner\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
store i32 0, i32* %1
%3 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @chown(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %8
%22 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %8
%25 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%32 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%33 = load i64, i64* %32
%34 = trunc i64 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%37 = load i64, i64* %36
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @chown(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 100, i32 -1)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %30
%44 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %30
%47 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %46
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%54 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%55 = load i64, i64* %54
%56 = trunc i64 %55 to i32
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%59 = load i64, i64* %58
%60 = trunc i64 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %60)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [19 x i8] c"fail to get status\00"
@.str.3 = [31 x i8] c"the owner of test.txt is : %d\0A\00"
@.str.4 = [31 x i8] c"the group of test.txt is : %d\0A\00"
@.str.6 = [21 x i8] c"fail to change owner\00"
@str = [22 x i8] c"before changing owner\00"
@str.9 = [21 x i8] c"after changing owner\00"
@str.10 = [15 x i8] c"nonexsit owner\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @chown(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 -1)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %8
%22 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %8
%25 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%32 = load i64, i64* %10
%33 = trunc i64 %32 to i32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i64, i64* %14
%36 = trunc i64 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = tail call i32 @putchar(i32 10)
%39 = tail call i32 @chown(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 100, i32 -1)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %30
%42 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %30
%45 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %44
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0))
%52 = load i64, i64* %10
%53 = trunc i64 %52 to i32
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i64, i64* %14
%56 = trunc i64 %55 to i32
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %56)
ret i32 0
}