#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 atoi(char const *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *);
int /*<<< orphan*/ printf(char *, int);
int read_battery_prop(int, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ write_battery_prop(int, char const *, char const *);
int main(int argc, const char *argv[]) {
  if ((argc < 4) || (argc == 4 && strcmp(argv[1], "-g") != 0) ||
      (argc == 5 && strcmp(argv[1], "-s") != 0) || (argc > 5)) {
    fprintf(stderr,
            "Usage:\n"
            "  %s -g BATT_ID BATT_PROP\n"
            "  %s -s BATT_ID BATT_PROP VALUE\n",
            argv[0], argv[0]);
    exit(1);
  }
  if (strcmp(argv[1], "-g") == 0) {
    int battery = atoi(argv[2]);
    const char *prop = argv[3];
    int val = read_battery_prop(battery, prop);
    printf("%d", val);
  } else if (strcmp(argv[1], "-s") == 0) {
    int battery = atoi(argv[2]);
    const char *prop = argv[3];
    const char *val = argv[4];
    write_battery_prop(battery, prop, val);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11ea <main+0x7a>
cmpl   $0x4,-0x8(%rbp)
jne    11b8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ea <main+0x7a>
cmpl   $0x5,-0x8(%rbp)
jne    11e0 <main+0x70>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ea <main+0x7a>
cmpl   $0x5,-0x8(%rbp)
jle    1217 <main+0xa7>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdda(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1274 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1090 <read_battery_prop@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
jmp    12cf <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd80(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12ca <main+0x15a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <write_battery_prop@plt>
jmp    12cf <main+0x15f>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x4,%edi
jl     1217 <main+0xa7>
cmp    $0x5,%edi
je     1198 <main+0x28>
cmp    $0x4,%edi
jne    1217 <main+0xa7>
mov    0x8(%rbx),%rdi
lea    0xe6a(%rip),%rsi
jmp    11a3 <main+0x33>
mov    0x8(%rbx),%rdi
lea    0xe60(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1217 <main+0xa7>
mov    0x8(%rbx),%rdi
lea    0xe48(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11f1 <main+0x81>
mov    0x8(%rbx),%rdi
lea    0xe36(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1213 <main+0xa3>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    0x18(%rbx),%rsi
mov    0x20(%rbx),%rdx
mov    %eax,%edi
call   1060 <write_battery_prop@plt>
jmp    1213 <main+0xa3>
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    0x18(%rbx),%rsi
mov    %eax,%edi
call   1090 <read_battery_prop@plt>
lea    0xe3c(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rcx
lea    0xddc(%rip),%rsi
mov    %rcx,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-g\00"
@.str.1 = [3 x i8] c"-s\00"
@stderr = global i32 0
@.str.2 = [66 x i8] c"Usage:\0A %s -g BATT_ID BATT_PROP\0A %s -s BATT_ID BATT_PROP VALUE\0A\00"
@.str.3 = [3 x i8] c"%d\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 i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %35, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 4
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %35, label %23
23: ; preds = %17, %14
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 5
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26, %23
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 5
br i1 %34, label %35, label %45
35: ; preds = %32, %26, %17, %2
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %45
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %6
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
store i8* %58, i8** %7
%59 = load i32, i32* %6
%60 = load i8*, i8** %7
%61 = call i32 @read_battery_prop(i32 %59, i8* %60)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %62)
br label %86
64: ; preds = %45
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 1
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %85
70: ; preds = %64
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i32 @atoi(i8* %73)
store i32 %74, i32* %9
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 3
%77 = load i8*, i8** %76
store i8* %77, i8** %10
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 4
%80 = load i8*, i8** %79
store i8* %80, i8** %11
%81 = load i32, i32* %9
%82 = load i8*, i8** %10
%83 = load i8*, i8** %11
%84 = call i32 @write_battery_prop(i32 %81, i8* %82, i8* %83)
br label %85
85: ; preds = %70, %64
br label %86
86: ; preds = %85, %51
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [3 x i8] c"-g\00"
@.str.1 = [3 x i8] c"-s\00"
@stderr = global i32 0
@.str.2 = [66 x i8] c"Usage:\0A %s -g BATT_ID BATT_PROP\0A %s -s BATT_ID BATT_PROP VALUE\0A\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %15, label %4
4: ; preds = %2
switch i32 %0, label %15 [
i32 4, label %5
i32 5, label %10
]
5: ; preds = %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %15
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %4, %10, %5, %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %5, %10
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = tail call i32 @read_battery_prop(i32 %28, i8* %30)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %46
33: ; preds = %20
%34 = load i8*, i8** %21
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = getelementptr inbounds i8*, i8** %1, i64 3
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8*, i8** %1, i64 4
%44 = load i8*, i8** %43
%45 = tail call i32 @write_battery_prop(i32 %40, i8* %42, i8* %44)
br label %46
46: ; preds = %33, %37, %25
ret i32 0
}