#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 */

/* Variables and functions */
int atoi(char *);
int chmod(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int mode;
  int mode_u;
  int mode_g;
  int mode_o;
  char *path;
  if (argc < 3) {
    printf("%s <mode num> <target file>\n", argv[0]);
    exit(0);
  }
  mode = atoi(argv[1]);
  if (mode > 777 || mode < 0) {
    printf("mode num error!\n");
    exit(0);
  }
  mode_u = mode / 100;
  mode_g = (mode - (mode_u * 100)) / 10;
  mode_o = mode - (mode_u * 100) - (mode_g * 10);
  mode = (mode_u * 8 * 8) + (mode_g * 8) + mode_o;
  path = argv[2];
  if (chmod(path, mode) == -1) {
    perror("chmod error");
    exit(1);
  }
  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)
cmpl   $0x3,-0x8(%rbp)
jge    118c <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x309,-0x14(%rbp)
jg     11b3 <main+0x63>
cmpl   $0x0,-0x14(%rbp)
jge    11c8 <main+0x78>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x64,-0x18(%rbp),%ecx
sub    %ecx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x64,-0x18(%rbp),%ecx
sub    %ecx,%eax
imul   $0xa,-0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x3,%eax
shl    $0x3,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
add    %ecx,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0xffffffff,%eax
jne    124a <main+0xfa>
lea    0xdf3(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    11bc <main+0x5c>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
cmp    $0x30a,%eax
jae    11d4 <main+0x74>
movzwl %ax,%ecx
shr    $0x2,%ecx
imul   $0x147b,%ecx,%esi
shr    $0x11,%esi
imul   $0xffffff9c,%esi,%ecx
add    %eax,%ecx
movswl %cx,%eax
imul   $0xffff9999,%eax,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x12,%eax
add    %edx,%eax
shl    $0x6,%esi
add    %eax,%eax
cwtl
add    %ecx,%esi
add    %eax,%esi
mov    0x10(%rbx),%rdi
call   1050 <chmod@plt>
cmp    $0xffffffff,%eax
je     11e7 <main+0x87>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe2f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"%s <mode num> <target file>\0A\00"
@.str.1 = [17 x i8] c"mode num error!\0A\00"
@.str.2 = [12 x i8] c"chmod error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 777
br i1 %25, label %29, label %26
26: ; preds = %19
%27 = load i32, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26, %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %26
%33 = load i32, i32* %6
%34 = sdiv i32 %33, 100
store i32 %34, i32* %7
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = mul nsw i32 %36, 100
%38 = sub nsw i32 %35, %37
%39 = sdiv i32 %38, 10
store i32 %39, i32* %8
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = mul nsw i32 %41, 100
%43 = sub nsw i32 %40, %42
%44 = load i32, i32* %8
%45 = mul nsw i32 %44, 10
%46 = sub nsw i32 %43, %45
store i32 %46, i32* %9
%47 = load i32, i32* %7
%48 = mul nsw i32 %47, 8
%49 = mul nsw i32 %48, 8
%50 = load i32, i32* %8
%51 = mul nsw i32 %50, 8
%52 = add nsw i32 %49, %51
%53 = load i32, i32* %9
%54 = add nsw i32 %52, %53
store i32 %54, i32* %6
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = load i32, i32* %6
%60 = call i32 @chmod(i8* %58, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %32
%63 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %32
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"%s <mode num> <target file>\0A\00"
@.str.2 = [12 x i8] c"chmod error\00"
@str = [16 x i8] c"mode num error!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp ugt i32 %11, 777
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %8
%17 = trunc i32 %11 to i16
%18 = udiv i16 %17, 100
%19 = zext i16 %18 to i32
%20 = mul nsw i32 %19, -100
%21 = add nsw i32 %20, %11
%22 = trunc i32 %21 to i16
%23 = sdiv i16 %22, -10
%24 = shl nuw nsw i32 %19, 6
%25 = shl nsw i16 %23, 1
%26 = sext i16 %25 to i32
%27 = add nsw i32 %21, %24
%28 = add nsw i32 %27, %26
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @chmod(i8* %30, i32 %28)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %16
%34 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %16
ret i32 0
}