#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 /*<<< orphan*/ assert(int);
scalar_t__ chmod(char *, unsigned long);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ send_errno(int /*<<< orphan*/);
int /*<<< orphan*/ send_success();
unsigned long strtol(char *, int /*<<< orphan*/, int);
void do_chmod(int argc, char **argv) {
  assert(argc == 2);
  unsigned long mode = strtol(argv[1], 0, 16);
  if (chmod(argv[0], mode) == 0) {
    send_success();
  } else {
    send_errno(errno);
  }
}


x86 assembly (clang, -O0):
<do_chmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <chmod@plt>
cmp    $0x0,%rax
jne    11ae <do_chmod+0x5e>
mov    $0x0,%al
call   1050 <send_success@plt>
jmp    11bc <do_chmod+0x6c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <send_errno@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_chmod>:
push   %rbx
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   1030 <assert@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    (%rbx),%rdi
mov    %rax,%rsi
call   1060 <chmod@plt>
test   %rax,%rax
je     1192 <do_chmod+0x42>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1070 <send_errno@plt>
xor    %eax,%eax
pop    %rbx
jmp    1050 <send_success@plt>

LLVM IR (-O0):
@errno = global i32 0
define void @do_chmod(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 2
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strtol(i8* %12, i32 0, i32 16)
store i64 %13, i64* %5
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i64, i64* %5
%18 = call i64 @chmod(i8* %16, i64 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (...) @send_success()
br label %25
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = call i32 @send_errno(i32 %23)
br label %25
25: ; preds = %22, %20
ret void
}

LLVM IR (-O2):
@errno = global i32 0
define void @do_chmod(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strtol(i8* %7, i32 0, i32 16)
%9 = load i8*, i8** %1
%10 = tail call i64 @chmod(i8* %9, i64 %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 (...) @send_success()
br label %17
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = tail call i32 @send_errno(i32 %15)
br label %17
17: ; preds = %14, %12
ret void
}