#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*/ O_RDWR;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  char *filename;
  char val;
  if (3 != argc) {
    usage();
    return 0;
  }
  filename = argv[1];
  fd = open(filename, O_RDWR);
  if (fd < 0) {
    printf("ERROR: %s open failed.\n", filename);
    return 0;
  }
  if (!strcmp("on", argv[2])) {
    val = 0;
    write(fd, &val, 1);
  } else if (!strcmp("off", argv[2])) {
    val = 1;
    write(fd, &val, 1);
  } else {
    usage();
    return 0;
  }
  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)
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
je     1187 <main+0x37>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    125b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ce <main+0x7e>
mov    -0x20(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125b <main+0x10b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe3b(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1205 <main+0xb5>
movb   $0x0,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1254 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe07(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    123c <main+0xec>
movb   $0x1,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    124f <main+0xff>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    125b <main+0x10b>
jmp    1254 <main+0x104>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    11a6 <main+0x56>
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11af <main+0x5f>
mov    %eax,%r14d
mov    0x10(%rbx),%rbx
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c0 <main+0x70>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c7 <main+0x77>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    11de <main+0x8e>
lea    0xe4a(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
jmp    11de <main+0x8e>
movb   $0x0,0xf(%rsp)
jmp    11cc <main+0x7c>
movb   $0x1,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [24 x i8] c"ERROR: %s open failed.\0A\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\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 i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 3, %9
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 0, i32* %3
br label %47
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i8*, i8** %7
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 0, i32* %3
br label %47
25: ; preds = %13
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
store i8 0, i8* %8
%32 = load i32, i32* %6
%33 = call i32 @write(i32 %32, i8* %8, i32 1)
br label %46
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
store i8 1, i8* %8
%41 = load i32, i32* %6
%42 = call i32 @write(i32 %41, i8* %8, i32 1)
br label %45
43: ; preds = %34
%44 = call i32 (...) @usage()
store i32 0, i32* %3
br label %47
45: ; preds = %40
br label %46
46: ; preds = %45, %31
store i32 0, i32* %3
br label %47
47: ; preds = %46, %43, %22, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [24 x i8] c"ERROR: %s open failed.\0A\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp eq i32 %0, 3
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (...) @usage()
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %29
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
store i8 0, i8* %3
%21 = call i32 @write(i32 %11, i8* %3, i32 1)
br label %29
22: ; preds = %15
%23 = tail call i32 @strcmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %17)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
store i8 1, i8* %3
%26 = call i32 @write(i32 %11, i8* %3, i32 1)
br label %29
27: ; preds = %22
%28 = tail call i32 (...) @usage()
br label %29
29: ; preds = %20, %25, %27, %13, %5
ret i32 0
}