#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 *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strstr(char *, char *);
int main(int argc, char **argv) {
  char buf[1024], *v;
  int red;
  if (argc != 2) {
    fprintf(stderr, "Use: chgvel <1/reduction>\n");
    return 1;
  }
  red = atoi(argv[1]);
  while (fgets(buf, 1024, stdin)) {
    if (strstr(buf, " On ") != NULL || strstr(buf, " Off ") != NULL) {
      if ((v = strstr(buf, "v=")) != NULL) {
        sprintf(v + 2, "%d\n", atoi(v + 2) * (red - 1) / red + (128 / red));
      }
    }
    printf("%s", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12b8 <main+0x158>
lea    -0x410(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
jne    1215 <main+0xb5>
lea    -0x410(%rbp),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12a0 <main+0x140>
lea    -0x410(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x418(%rbp)
cmp    $0x0,%rax
je     129b <main+0x13b>
mov    -0x418(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x428(%rbp)
mov    -0x418(%rbp),%rdi
add    $0x2,%rdi
call   1060 <atoi@plt>
mov    -0x428(%rbp),%rdi
mov    -0x41c(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
cltd
idivl  -0x41c(%rbp)
mov    %eax,-0x420(%rbp)
mov    $0x80,%eax
cltd
idivl  -0x41c(%rbp)
mov    -0x420(%rbp),%edx
add    %eax,%edx
lea    0xd93(%rip),%rsi
call   1070 <sprintf@plt>
jmp    12a0 <main+0x140>
lea    -0x410(%rbp),%rsi
lea    0xd7f(%rip),%rdi
call   1030 <printf@plt>
jmp    11b7 <main+0x57>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jne    125b <main+0xfb>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1277 <main+0x117>
mov    %ebp,%r13d
add    $0xffffffff,%r13d
lea    0xe69(%rip),%r14
mov    %rsp,%rbx
lea    0xe71(%rip),%r12
jmp    11ea <main+0x8a>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1277 <main+0x117>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
jne    120e <main+0xae>
mov    %rbx,%rdi
lea    0xe1c(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    %rbx,%rdi
lea    0xe0e(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    %rax,%r15
add    $0x2,%r15
mov    %r15,%rdi
call   1060 <atoi@plt>
imul   %r13d,%eax
cltd
idiv   %ebp
mov    %eax,%ecx
mov    $0x80,%eax
xor    %edx,%edx
idiv   %ebp
add    %eax,%ecx
mov    %r15,%rdi
lea    0xdda(%rip),%rsi
mov    %ecx,%edx
call   1070 <sprintf@plt>
jmp    11c0 <main+0x60>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1279 <main+0x119>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Use: chgvel <1/reduction>\0A\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c" On \00"
@.str.2 = [6 x i8] c" Off \00"
@.str.3 = [3 x i8] c"v=\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i32
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, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %56
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %8
br label %19
19: ; preds = %52, %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i64 @fgets(i8* %20, i32 1024, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %55
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i8* @strstr(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %52
32: ; preds = %28, %24
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i8* @strstr(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i8* %34, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %51
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = load i8*, i8** %7
%40 = getelementptr inbounds i8, i8* %39, i64 2
%41 = call i32 @atoi(i8* %40)
%42 = load i32, i32* %8
%43 = sub nsw i32 %42, 1
%44 = mul nsw i32 %41, %43
%45 = load i32, i32* %8
%46 = sdiv i32 %44, %45
%47 = load i32, i32* %8
%48 = sdiv i32 128, %47
%49 = add nsw i32 %46, %48
%50 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %36, %32
br label %52
52: ; preds = %51, %28
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%54 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %53)
br label %19
55: ; preds = %19
store i32 0, i32* %3
br label %56
56: ; preds = %55, %11
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Use: chgvel <1/reduction>\0A\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c" On \00"
@.str.2 = [6 x i8] c" Off \00"
@.str.3 = [3 x i8] c"v=\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %40
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = load i32, i32* @stdin
%14 = call i64 @fgets(i8* %4, i32 1024, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %9
%17 = add nsw i32 %12, -1
br label %18
18: ; preds = %16, %35
%19 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %35, label %24
24: ; preds = %21, %18
%25 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %35, label %27
27: ; preds = %24
%28 = getelementptr inbounds i8, i8* %25, i64 2
%29 = call i32 @atoi(i8* %28)
%30 = mul nsw i32 %29, %17
%31 = sdiv i32 %30, %12
%32 = sdiv i32 128, %12
%33 = add nsw i32 %32, %31
%34 = call i32 @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %24, %27, %21
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%37 = load i32, i32* @stdin
%38 = call i64 @fgets(i8* %4, i32 1024, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %18
40: ; preds = %35, %9, %6
%41 = phi i32 [ 1, %6 ], [ 0, %9 ], [ 0, %35 ]
ret i32 %41
}