#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 */
int chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ sscanf(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  mode_t mode;
  char *file;
  if (3 != argc) {
    printf("usage: %s <mode> <file>\n", argv[0]);
    return 1;
  }
  if ((sscanf(argv[1], "%o", &mode)) == 0) {
    fprintf(stderr, "invalid format\n");
    return 1;
  }
  file = argv[2];
  if ((chmod(file, mode)) == -1) {
    error(1, errno, "chmod failed");
  }
  return 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)
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
je     1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe77(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x0,%rax
jne    11d6 <main+0x86>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1218 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <chmod@plt>
cmp    $0xffffffff,%eax
jne    1211 <main+0xc1>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe20(%rip),%rdx
call   1070 <error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a7 <main+0x57>
mov    0x8(%rbx),%rdi
lea    0xeb1(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
test   %rax,%rax
je     11b8 <main+0x68>
mov    0x10(%rbx),%rdi
mov    0xc(%rsp),%esi
call   1060 <chmod@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    11d2 <main+0x82>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
jmp    11d2 <main+0x82>
mov    (%rbx),%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    11cd <main+0x7d>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"usage: %s <mode> <file>\0A\00"
@.str.1 = [3 x i8] c"%o\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"invalid format\0A\00"
@errno = global i32 0
@.str.3 = [13 x i8] c"chmod failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 3, %8
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %36
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %36
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = load i32, i32* %6
%30 = call i32 @chmod(i8* %28, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* @errno
%34 = call i32 @error(i32 1, i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %24
store i32 0, i32* %3
br label %36
36: ; preds = %35, %21, %10
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [25 x i8] c"usage: %s <mode> <file>\0A\00"
@.str.1 = [3 x i8] c"%o\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"invalid format\0A\00"
@errno = global i32 0
@.str.3 = [13 x i8] c"chmod failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %26
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = load i32, i32* %3
%21 = call i32 @chmod(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = call i32 @error(i32 1, i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %17, %23, %14, %6
%27 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %23 ], [ 0, %17 ]
ret i32 %27
}