#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*/ print_usage(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  char *filename;
  char val;
  if (argc != 3) {
    print_usage(argv[0]);
    return 0;
  }
  filename = argv[1];
  fd = open(filename, O_RDWR);
  if (fd < 0) {
    printf("error, can't open %s\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 {
    print_usage(argv[0]);
    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)
cmpl   $0x3,-0x8(%rbp)
je     1188 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <main+0x111>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cf <main+0x7f>
mov    -0x20(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <main+0x111>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe38(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1206 <main+0xb6>
movb   $0x0,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    125a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe04(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    123d <main+0xed>
movb   $0x1,-0x21(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1255 <main+0x105>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1261 <main+0x111>
jmp    125a <main+0x10a>
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
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a6 <main+0x56>
mov    0x8(%rbx),%rbp
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11b0 <main+0x60>
mov    %eax,%r14d
mov    0x10(%rbx),%rbp
lea    0xe8f(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c1 <main+0x71>
lea    0xe7f(%rip),%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11c8 <main+0x78>
mov    (%rbx),%rdi
call   1070 <print_usage@plt>
jmp    11df <main+0x8f>
lea    0xe49(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
jmp    11df <main+0x8f>
movb   $0x0,0xf(%rsp)
jmp    11cd <main+0x7d>
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 = [22 x i8] c"error, can't open %s\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 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @print_usage(i8* %14)
store i32 0, i32* %3
br label %53
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i8*, i8** %7
%27 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 0, i32* %3
br label %53
28: ; preds = %16
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %28
store i8 0, i8* %8
%35 = load i32, i32* %6
%36 = call i32 @write(i32 %35, i8* %8, i32 1)
br label %52
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %37
store i8 1, i8* %8
%44 = load i32, i32* %6
%45 = call i32 @write(i32 %44, i8* %8, i32 1)
br label %51
46: ; preds = %37
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @print_usage(i8* %49)
store i32 0, i32* %3
br label %53
51: ; preds = %43
br label %52
52: ; preds = %51, %34
store i32 0, i32* %3
br label %53
53: ; preds = %52, %46, %25, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [22 x i8] c"error, can't open %s\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 %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @print_usage(i8* %6)
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %31
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
store i8 0, i8* %3
%22 = call i32 @write(i32 %12, i8* %3, i32 1)
br label %31
23: ; preds = %16
%24 = tail call i32 @strcmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %18)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
store i8 1, i8* %3
%27 = call i32 @write(i32 %12, i8* %3, i32 1)
br label %31
28: ; preds = %23
%29 = load i8*, i8** %1
%30 = tail call i32 @print_usage(i8* %29)
br label %31
31: ; preds = %21, %26, %28, %14, %5
ret i32 0
}