#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 /*<<< orphan*/, int);
int /*<<< orphan*/ exit(int);
int lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(void) {
  struct stat statbuf;
  printf("before changing\n");
  if (stat("test.txt", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("the owner of test.txt is : %u\n", (unsigned int)statbuf.st_uid);
  printf("the group of test.txt is : %u\n", (unsigned int)statbuf.st_gid);
  if (lstat("sl", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("the owner of sl is : %u\n", (unsigned int)statbuf.st_uid);
  printf("the group of sl is : %u\n", (unsigned int)statbuf.st_gid);
  if (chown("sl", 0, -1) == -1) {
    perror("fail to change owner");
    exit(1);
  }
  printf("after changing\n");
  if (stat("test.txt", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("the owner of test.txt is : %u\n", (unsigned int)statbuf.st_uid);
  printf("the group of test.txt is : %u\n", (unsigned int)statbuf.st_gid);
  if (lstat("sl", &statbuf) == -1) {
    perror("fail to get status");
    exit(1);
  }
  printf("the owner of sl is : %u\n", (unsigned int)statbuf.st_uid);
  printf("the group of sl is : %u\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    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    11ac <main+0x4c>
lea    0xe7d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0xa3>
lea    0xe26(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe39(%rip),%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1060 <chown@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0xfd>
lea    0xe52(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd9f(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    129a <main+0x13a>
lea    0xd8f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xda2(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
jne    12f1 <main+0x191>
lea    0xd38(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xd75(%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    0xf29(%rip),%rdi
call   1030 <puts@plt>
lea    0xe79(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x12f>
mov    0x10(%rsp),%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x12f>
mov    0x10(%rsp),%esi
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1070 <chown@plt>
cmp    $0xffffffff,%eax
je     12a8 <main+0x138>
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd5(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x12f>
mov    0x10(%rsp),%esi
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf5(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x12f>
mov    0x10(%rsp),%esi
lea    0xdde(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xd63(%rip),%rdi
jmp    12af <main+0x13f>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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