#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 */
unsigned int ATTR_NONE;
unsigned int FAT_IOCTL_GET_ATTRIBUTES;
unsigned int FAT_IOCTL_SET_ATTRIBUTES;
unsigned int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ hex_print(char *, int);
int ioctl(int, unsigned int, unsigned long);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcasecmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  unsigned int cmd = 0;
  unsigned int attr = ATTR_NONE;
  int ret = 0;
  int fd = 0;
  if (argc < 4) {
    fprintf(stderr, "usage: %s [get|set] filename [BASE_10_VALUE]\n", argv[0]);
    return -1;
  }
  fd = open(argv[2], 0);
  if (fd < 0) {
    fprintf(stderr, "can't open file: %s\n", argv[2]);
    return -1;
  } else {
    printf("opened file: %s\n", argv[2]);
  }
  if (strcasecmp(argv[1], "set") == 0) {
    attr = atoi(argv[3]);
    cmd = FAT_IOCTL_SET_ATTRIBUTES;
  } else if (strcasecmp(argv[1], "get") == 0) {
    cmd = FAT_IOCTL_GET_ATTRIBUTES;
  } else {
    fprintf(stderr, "unknown option %s\n", argv[1]);
    goto quit;
  }
  if ((ret = ioctl(fd, cmd, (unsigned long)&attr)) != 0) {
    fprintf(stderr, "ioctl: %s\n", strerror(errno));
  }
  if (ret > -1) {
    if (argv[1][0] == 's') {
      printf("set file attributes to ");
    } else if (argv[1][0] == 'g') {
      printf("file attributes are ");
    }
    hex_print((char *)&attr, 1);
    printf("\n");
  }
quit:
  close(fd);
  return ret;
}


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)
movl   $0x0,-0x14(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11f9 <main+0x69>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe18(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %esi,%esi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    123e <main+0xae>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe01(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b7 <main+0x227>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf1(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1293 <main+0x103>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12e9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb6(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    12c2 <main+0x132>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12e4 <main+0x154>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd82(%rip),%rsi
call   1080 <fprintf@plt>
jmp    13a9 <main+0x219>
jmp    12e9 <main+0x159>
mov    -0x20(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1060 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1330 <main+0x1a0>
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xd44(%rip),%rsi
call   1080 <fprintf@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jle    13a4 <main+0x214>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x73,%eax
jne    1361 <main+0x1d1>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1388 <main+0x1f8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x67,%eax
jne    1383 <main+0x1f3>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1388 <main+0x1f8>
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <hex_print@plt>
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a9 <main+0x219>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
cmp    $0x3,%edi
jg     11d4 <main+0x34>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe31(%rip),%rsi
jmp    1257 <main+0xb7>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
call   10a0 <open@plt>
test   %eax,%eax
js     1243 <main+0xa3>
mov    %eax,%r14d
mov    0x10(%rbx),%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%rbp
lea    0xe51(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     1266 <main+0xc6>
lea    0xe41(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     127c <main+0xdc>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %rbp,%rdx
call   1090 <fprintf@plt>
xor    %ebp,%ebp
jmp    1304 <main+0x164>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xdd7(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    130c <main+0x16c>
mov    0x18(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x2d3e(%rip),%rax
jmp    1283 <main+0xe3>
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   1070 <ioctl@plt>
mov    %eax,%ebp
test   %eax,%eax
je     12c6 <main+0x126>
mov    0x2d31(%rip),%rax
mov    (%rax),%r15d
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdb8(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
test   %ebp,%ebp
js     1304 <main+0x164>
mov    0x8(%rbx),%rax
mov    (%rax),%al
cmp    $0x73,%al
je     12dd <main+0x13d>
cmp    $0x67,%al
jne    12eb <main+0x14b>
lea    0xdb7(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xd96(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
call   1050 <hex_print@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ATTR_NONE = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"usage: %s [get|set] filename [BASE_10_VALUE]\0A\00"
@.str.1 = [21 x i8] c"can't open file: %s\0A\00"
@.str.2 = [17 x i8] c"opened file: %s\0A\00"
@.str.3 = [4 x i8] c"set\00"
@FAT_IOCTL_SET_ATTRIBUTES = global i32 0
@.str.4 = [4 x i8] c"get\00"
@FAT_IOCTL_GET_ATTRIBUTES = global i32 0
@.str.5 = [19 x i8] c"unknown option %s\0A\00"
@.str.6 = [11 x i8] c"ioctl: %s\0A\00"
@errno = global i32 0
@.str.7 = [24 x i8] c"set file attributes to \00"
@.str.8 = [21 x i8] c"file attributes are \00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* @ATTR_NONE
store i32 %10, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %3
br label %108
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @open(i8* %22, i32 0)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %108
32: ; preds = %19
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %32
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i64 @strcasecmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %37
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %7
%48 = load i32, i32* @FAT_IOCTL_SET_ATTRIBUTES
store i32 %48, i32* %6
br label %64
49: ; preds = %37
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @strcasecmp(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %49
%56 = load i32, i32* @FAT_IOCTL_GET_ATTRIBUTES
store i32 %56, i32* %6
br label %63
57: ; preds = %49
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %61)
br label %104
63: ; preds = %55
br label %64
64: ; preds = %63, %43
%65 = load i32, i32* %9
%66 = load i32, i32* %6
%67 = ptrtoint i32* %7 to i64
%68 = call i32 @ioctl(i32 %65, i32 %66, i64 %67)
store i32 %68, i32* %8
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %64
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %70, %64
%76 = load i32, i32* %8
%77 = icmp sgt i32 %76, -1
br i1 %77, label %78, label %103
78: ; preds = %75
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = getelementptr inbounds i8, i8* %81, i64 0
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 115
br i1 %85, label %86, label %88
86: ; preds = %78
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %99
88: ; preds = %78
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = getelementptr inbounds i8, i8* %91, i64 0
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 103
br i1 %95, label %96, label %98
96: ; preds = %88
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %98
98: ; preds = %96, %88
br label %99
99: ; preds = %98, %86
%100 = bitcast i32* %7 to i8*
%101 = call i32 @hex_print(i8* %100, i32 1)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %103
103: ; preds = %99, %75
br label %104
104: ; preds = %103, %57
%105 = load i32, i32* %9
%106 = call i32 @close(i32 %105)
%107 = load i32, i32* %8
store i32 %107, i32* %3
br label %108
108: ; preds = %104, %26, %13
%109 = load i32, i32* %3
ret i32 %109
}

LLVM IR (-O2):
@ATTR_NONE = global i32 0
@stderr = global i32 0
@.str = [46 x i8] c"usage: %s [get|set] filename [BASE_10_VALUE]\0A\00"
@.str.1 = [21 x i8] c"can't open file: %s\0A\00"
@.str.2 = [17 x i8] c"opened file: %s\0A\00"
@.str.3 = [4 x i8] c"set\00"
@FAT_IOCTL_SET_ATTRIBUTES = global i32 0
@.str.4 = [4 x i8] c"get\00"
@FAT_IOCTL_GET_ATTRIBUTES = global i32 0
@.str.5 = [19 x i8] c"unknown option %s\0A\00"
@.str.6 = [11 x i8] c"ioctl: %s\0A\00"
@errno = global i32 0
@.str.7 = [24 x i8] c"set file attributes to \00"
@.str.8 = [21 x i8] c"file attributes are \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @ATTR_NONE
store i32 %5, i32* %3
%6 = icmp slt i32 %0, 4
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %62
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @open(i8* %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %62
20: ; preds = %11
%21 = load i8*, i8** %12
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @strcasecmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
store i32 %30, i32* %3
br label %37
31: ; preds = %20
%32 = tail call i64 @strcasecmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %59
37: ; preds = %31, %27
%38 = phi i32* [ @FAT_IOCTL_SET_ATTRIBUTES, %27 ], [ @FAT_IOCTL_GET_ATTRIBUTES, %31 ]
%39 = load i32, i32* %38
%40 = ptrtoint i32* %3 to i64
%41 = call i32 @ioctl(i32 %14, i32 %39, i64 %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %46)
%48 = icmp sgt i32 %41, -1
br i1 %48, label %49, label %59
49: ; preds = %37, %43
%50 = load i8*, i8** %23
%51 = load i8, i8* %50
switch i8 %51, label %56 [
i8 115, label %53
i8 103, label %52
]
52: ; preds = %49
br label %53
53: ; preds = %49, %52
%54 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), %52 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), %49 ]
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %54)
br label %56
56: ; preds = %53, %49
%57 = call i32 @hex_print(i8* %4, i32 1)
%58 = call i32 @putchar(i32 10)
br label %59
59: ; preds = %43, %56, %34
%60 = phi i32 [ %41, %56 ], [ %41, %43 ], [ 0, %34 ]
%61 = call i32 @close(i32 %14)
br label %62
62: ; preds = %59, %16, %7
%63 = phi i32 [ -1, %7 ], [ -1, %16 ], [ %60, %59 ]
ret i32 %63
}