#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 */
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
scalar_t__ chmod(char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  mode_t mode;
  if (argc != 3) {
    printf("usage: %s mode name\n", argv[0]);
    return 1;
  }
  mode = strtoul(argv[1], NULL, 8);
  return chmod(argv[2], mode) ? errno : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     116f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c3 <main+0x93>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
cmp    $0x0,%rax
je     11b3 <main+0x83>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11bd <main+0x8d>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    11bd <main+0x8d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    116b <main+0x3b>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <strtoul@plt>
mov    0x10(%rbx),%rdi
mov    %eax,%esi
call   1040 <chmod@plt>
test   %rax,%rax
je     1180 <main+0x50>
mov    0x2e7a(%rip),%rax
mov    (%rax),%r14d
jmp    1180 <main+0x50>
mov    (%rbx),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"usage: %s mode name\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %3
br label %30
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strtoul(i8* %17, i32* null, i32 8)
store i32 %18, i32* %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* %6
%23 = call i64 @chmod(i8* %21, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = load i32, i32* @errno
br label %28
27: ; preds = %14
br label %28
28: ; preds = %27, %25
%29 = phi i32 [ %26, %25 ], [ 0, %27 ]
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [21 x i8] c"usage: %s mode name\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strtoul(i8* nocapture %9, i32* null, i32 8)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i64 @chmod(i8* %12, i32 %10)
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* @errno
%16 = select i1 %14, i32 0, i32 %15
br label %17
17: ; preds = %7, %4
%18 = phi i32 [ 1, %4 ], [ %16, %7 ]
ret i32 %18
}