#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*/ usleep(int);
int write_int(char *, int);
int transition(int cur, int desired, int duration) {
  int delta;
  int step;
  int delay;
  delta = desired - cur;
  if (delta == 0)
    return 0;
  else if (delta < 0) {
    delta = -delta;
    step = -1;
  } else
    step = 1;
  delay = duration / delta;
  while (cur != desired) {
    cur += step;
    if (write_int("/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/"
                  "brightness",
                  cur) == -1)
      return -1;
    usleep(delay);
  }
  return 0;
}


x86 assembly (clang, -O0):
<transition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1150 <transition+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11d1 <transition+0xb1>
cmpl   $0x0,-0x14(%rbp)
jge    116e <transition+0x4e>
xor    %eax,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
jmp    1175 <transition+0x55>
movl   $0x1,-0x18(%rbp)
jmp    117a <transition+0x5a>
mov    -0x10(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11ca <transition+0xaa>
mov    -0x18(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe5d(%rip),%rdi
call   1030 <write_int@plt>
cmp    $0xffffffff,%eax
jne    11bd <transition+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <transition+0xb1>
mov    -0x1c(%rbp),%edi
call   1040 <usleep@plt>
jmp    1184 <transition+0x64>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    %esi,%ecx
sub    %edi,%ecx
je     1186 <transition+0x66>
mov    %esi,%r13d
mov    %edi,%ebx
mov    %ecx,%esi
neg    %esi
cmovs  %ecx,%esi
mov    %edx,%eax
cltd
idiv   %esi
cmp    %edi,%r13d
je     1186 <transition+0x66>
mov    %eax,%r15d
not    %ecx
shr    $0x1f,%ecx
lea    (%rcx,%rcx,1),%ebp
add    $0xffffffff,%ebp
lea    0xea1(%rip),%r12
nop
add    %ebp,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <write_int@plt>
cmp    $0xffffffff,%eax
je     1180 <transition+0x60>
mov    %r15d,%edi
call   1040 <usleep@plt>
cmp    %ebx,%r13d
jne    1160 <transition+0x40>
jmp    1186 <transition+0x66>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness\00"
define i32 @transition(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %6
%12 = load i32, i32* %5
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %45
17: ; preds = %3
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %8
%22 = sub nsw i32 0, %21
store i32 %22, i32* %8
store i32 -1, i32* %9
br label %24
23: ; preds = %17
store i32 1, i32* %9
br label %24
24: ; preds = %23, %20
br label %25
25: ; preds = %24
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = sdiv i32 %26, %27
store i32 %28, i32* %10
br label %29
29: ; preds = %41, %25
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i32, i32* %9
%35 = load i32, i32* %5
%36 = add nsw i32 %35, %34
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = call i32 @write_int(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %33
store i32 -1, i32* %4
br label %45
41: ; preds = %33
%42 = load i32, i32* %10
%43 = call i32 @usleep(i32 %42)
br label %29
44: ; preds = %29
store i32 0, i32* %4
br label %45
45: ; preds = %44, %40, %16
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [70 x i8] c"/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/brightness\00"
define i32 @transition(i32 %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %1, %0
%5 = icmp eq i32 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = icmp slt i32 %4, 0
%8 = sub nsw i32 0, %4
%9 = select i1 %7, i32 %8, i32 %4
%10 = select i1 %7, i32 -1, i32 1
%11 = sdiv i32 %2, %9
%12 = icmp eq i32 %1, %0
br i1 %12, label %21, label %13
13: ; preds = %6, %18
%14 = phi i32 [ %15, %18 ], [ %0, %6 ]
%15 = add nsw i32 %14, %10
%16 = tail call i32 @write_int(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i32 @usleep(i32 %11)
%20 = icmp eq i32 %15, %1
br i1 %20, label %21, label %13
21: ; preds = %13, %18, %6, %3
%22 = phi i32 [ 0, %3 ], [ 0, %6 ], [ -1, %13 ], [ 0, %18 ]
ret i32 %22
}