#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_mode;
};

/* Variables and functions */
int S_ISGID;
int S_ISUID;
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int i;
  char *p;
  struct stat buf;
  for (i = 1; i < argc; ++i) {
    p = argv[i];
    if (lstat(p, &buf) < 0) {
      perror("lstat error");
      continue;
    }
    if (buf.st_mode & S_ISUID) {
      printf("IS UID\n");
    }
    if (buf.st_mode & S_ISGID) {
      printf("IS GID\n");
    }
    buf.st_mode |= S_ISUID;
  }
  return 0;
}


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   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f0 <main+0xc0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jge    1191 <main+0x61>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
jmp    11e2 <main+0xb2>
mov    -0x28(%rbp),%eax
mov    0x2e4d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b2 <main+0x82>
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
mov    0x2e1c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11d3 <main+0xa3>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11c0 <main+0x90>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r15d
mov    %rsp,%r14
mov    0x2e8f(%rip),%r12
nopl   0x0(%rax)
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1040 <lstat@plt>
test   %rax,%rax
js     11b2 <main+0x82>
mov    (%rsp),%r13d
test   %r13d,(%r12)
je     1187 <main+0x57>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e4a(%rip),%rax
test   %r13d,(%rax)
je     119f <main+0x6f>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
or     (%r12),%r13d
mov    %r13d,(%rsp)
add    $0x1,%r15
cmp    %r15,%rbp
jne    1160 <main+0x30>
jmp    11c0 <main+0x90>
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
jmp    11a7 <main+0x77>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"lstat error\00"
@S_ISUID = global i32 0
@.str.1 = [8 x i8] c"IS UID\0A\00"
@S_ISGID = global i32 0
@.str.2 = [8 x i8] c"IS GID\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %9
9: ; preds = %45, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %48
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = call i64 @lstat(i8* %19, %struct.stat* %8)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %45
24: ; preds = %13
%25 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @S_ISUID
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i32, i32* @S_ISGID
%36 = and i32 %34, %35
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
%41 = load i32, i32* @S_ISUID
%42 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%43 = load i32, i32* %42
%44 = or i32 %43, %41
store i32 %44, i32* %42
br label %45
45: ; preds = %40, %22
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %9
48: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"lstat error\00"
@S_ISUID = global i32 0
@S_ISGID = global i32 0
@str = [7 x i8] c"IS GID\00"
@str.3 = [7 x i8] c"IS UID\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %36
6: ; preds = %2
%7 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %6, %33
%10 = phi i64 [ 1, %6 ], [ %34, %33 ]
%11 = getelementptr inbounds i8*, i8** %1, i64 %10
%12 = load i8*, i8** %11
%13 = call i64 @lstat(i8* %12, %struct.stat* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %33
17: ; preds = %9
%18 = load i32, i32* %7
%19 = load i32, i32* @S_ISUID
%20 = and i32 %19, %18
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = load i32, i32* @S_ISGID
%26 = and i32 %25, %18
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* @S_ISUID
%32 = or i32 %31, %18
store i32 %32, i32* %7
br label %33
33: ; preds = %30, %15
%34 = add nuw nsw i64 %10, 1
%35 = icmp eq i64 %34, %8
br i1 %35, label %36, label %9
36: ; preds = %33, %2
ret i32 0
}