#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*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int maxHeight, height, upDist, decDist, fatigueFactor, downDist, day;
  while (1) {
    scanf("%d", &maxHeight);
    if (!maxHeight)
      break;
    scanf("%d %d %d", &upDist, &downDist, &fatigueFactor);
    maxHeight *= 100;
    upDist *= 100;
    downDist *= 100;
    decDist = fatigueFactor * upDist / 100;
    day = 0;
    height = 0;
    while (height >= 0 && height <= maxHeight) {
      day++;
      height += upDist;
      if (height > maxHeight)
        break;
      height -= downDist;
      upDist -= decDist;
      if (upDist < 0)
        upDist = 0;
    }
    if (height < 0)
      printf("failure on day %d\n", day);
    else
      printf("success on day %d\n", day);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1150 <main+0x30>
jmp    124b <main+0x12b>
lea    0xea9(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
imul   $0x64,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
imul   $0x64,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0x64,-0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x21(%rbp)
jl     11ba <main+0x9a>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ca <main+0xaa>
jmp    1219 <main+0xf9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    11ed <main+0xcd>
jmp    1219 <main+0xf9>
mov    -0x1c(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1214 <main+0xf4>
movl   $0x0,-0x10(%rbp)
jmp    119f <main+0x7f>
cmpl   $0x0,-0xc(%rbp)
jge    1237 <main+0x117>
mov    -0x20(%rbp),%esi
lea    0xddc(%rip),%rdi
call   1030 <printf@plt>
jmp    1246 <main+0x126>
mov    -0x20(%rbp),%esi
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xed1(%rip),%rdi
xor    %r15d,%r15d
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     124c <main+0x12c>
lea    0x14(%rsp),%r12
lea    0xeab(%rip),%rbp
lea    0x8(%rsp),%r13
jmp    119f <main+0x7f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
test   %edi,%edi
js     1240 <main+0x120>
lea    0xe9d(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
je     124c <main+0x12c>
xor    %r14d,%r14d
lea    0xe57(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%esi
imul   $0x64,%esi,%eax
mov    %eax,0x8(%rsp)
imul   $0x64,0xc(%rsp),%ecx
mov    %ecx,0xc(%rsp)
imul   $0x64,0x10(%rsp),%edx
mov    %edx,0x10(%rsp)
test   %esi,%esi
js     1178 <main+0x58>
mov    0x14(%rsp),%esi
imul   %ecx,%esi
movslq %esi,%rsi
imul   $0xffffffffae147ae1,%rsi,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
add    %edi,%esi
xor    %edi,%edi
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%r14d
add    %ecx,%edi
cmp    %eax,%edi
jg     1170 <main+0x50>
add    %esi,%ecx
cmovs  %r15d,%ecx
sub    %edx,%edi
mov    %ecx,0xc(%rsp)
js     1170 <main+0x50>
lea    0x1(%r14),%ebx
cmp    %eax,%edi
jle    1210 <main+0xf0>
jmp    1170 <main+0x50>
nopl   0x0(%rax)
lea    0xdc2(%rip),%rdi
jmp    117f <main+0x5f>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [19 x i8] c"failure on day %d\0A\00"
@.str.3 = [19 x i8] c"success on day %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
br label %9
9: ; preds = %0, %65
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
br label %66
14: ; preds = %9
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %7, i32* %6)
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, 100
store i32 %17, i32* %2
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 100
store i32 %19, i32* %4
%20 = load i32, i32* %7
%21 = mul nsw i32 %20, 100
store i32 %21, i32* %7
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = mul nsw i32 %22, %23
%25 = sdiv i32 %24, 100
store i32 %25, i32* %5
store i32 0, i32* %8
store i32 0, i32* %3
br label %26
26: ; preds = %55, %14
%27 = load i32, i32* %3
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = icmp sle i32 %30, %31
br label %33
33: ; preds = %29, %26
%34 = phi i1 [ false, %26 ], [ %32, %29 ]
br i1 %34, label %35, label %56
35: ; preds = %33
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = add nsw i32 %39, %38
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = load i32, i32* %2
%43 = icmp sgt i32 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %35
br label %56
45: ; preds = %35
%46 = load i32, i32* %7
%47 = load i32, i32* %3
%48 = sub nsw i32 %47, %46
store i32 %48, i32* %3
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, %49
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %45
store i32 0, i32* %4
br label %55
55: ; preds = %54, %45
br label %26
56: ; preds = %44, %33
%57 = load i32, i32* %3
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* %8
%61 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %65
62: ; preds = %56
%63 = load i32, i32* %8
%64 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %59
br label %9
66: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [19 x i8] c"failure on day %d\0A\00"
@.str.3 = [19 x i8] c"success on day %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp eq i32 %10, 0
br i1 %11, label %51, label %12
12: ; preds = %0, %47
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %4, i32* %3)
%14 = load i32, i32* %1
%15 = mul nsw i32 %14, 100
store i32 %15, i32* %1
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, 100
store i32 %17, i32* %2
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 100
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = mul nsw i32 %20, %17
%22 = sdiv i32 %21, -100
%23 = icmp sgt i32 %14, -1
br i1 %23, label %24, label %44
24: ; preds = %12, %31
%25 = phi i32 [ %28, %31 ], [ 0, %12 ]
%26 = phi i32 [ %32, %31 ], [ 0, %12 ]
%27 = phi i32 [ %35, %31 ], [ %17, %12 ]
%28 = add nuw nsw i32 %25, 1
%29 = add nsw i32 %27, %26
%30 = icmp sgt i32 %29, %15
br i1 %30, label %39, label %31
31: ; preds = %24
%32 = sub nsw i32 %29, %19
%33 = add i32 %27, %22
%34 = icmp sgt i32 %33, 0
%35 = select i1 %34, i32 %33, i32 0
store i32 %35, i32* %2
%36 = icmp sgt i32 %32, -1
%37 = icmp sle i32 %32, %15
%38 = select i1 %36, i1 %37, i1 false
br i1 %38, label %24, label %39
39: ; preds = %31, %24
%40 = phi i32 [ %32, %31 ], [ %29, %24 ]
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %47
44: ; preds = %12, %39
%45 = phi i32 [ %28, %39 ], [ 0, %12 ]
%46 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %42
%48 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %12
51: ; preds = %47, %0
ret i32 0
}