#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*/ exit(int);
int /*<<< orphan*/ printf(char *, int const);
int dpi_convert(const int dpi_value) {
  int dpi_hex = 0;
  if ((dpi_value != 0) && (200 <= dpi_value) && (dpi_value <= 5700) &&
      (dpi_value % 100 == 0)) {
    int rest = dpi_value % 400;
    int add_value = 0;
    switch (rest) {
    case 0:
      add_value = 0;
      break;
    case 100:
      add_value = 4;
      break;
    case 200:
      add_value = 9;
      break;
    case 300:
      add_value = 13;
      break;
    default:
      printf("%i is not a valid DPI value", dpi_value);
      exit(1);
    }
    dpi_hex = (dpi_value / 400) * 17 + add_value;
  } else {
    printf("%i is not a valid DPI value", dpi_value);
    exit(1);
  }
  return dpi_hex;
}


x86 assembly (clang, -O0):
<dpi_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1243 <dpi_convert+0x123>
mov    $0xc8,%eax
cmp    -0x4(%rbp),%eax
jg     1243 <dpi_convert+0x123>
cmpl   $0x1644,-0x4(%rbp)
jg     1243 <dpi_convert+0x123>
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1243 <dpi_convert+0x123>
movslq -0x4(%rbp),%rcx
mov    %ecx,%eax
imul   $0x51eb851f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x190,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     11e1 <dpi_convert+0xc1>
jmp    11aa <dpi_convert+0x8a>
mov    -0x14(%rbp),%eax
sub    $0x64,%eax
je     11ed <dpi_convert+0xcd>
jmp    11bb <dpi_convert+0x9b>
mov    -0x14(%rbp),%eax
sub    $0xc8,%eax
je     11f9 <dpi_convert+0xd9>
jmp    11ce <dpi_convert+0xae>
mov    -0x14(%rbp),%eax
sub    $0x12c,%eax
je     1205 <dpi_convert+0xe5>
jmp    1211 <dpi_convert+0xf1>
movl   $0x0,-0x10(%rbp)
jmp    122a <dpi_convert+0x10a>
movl   $0x4,-0x10(%rbp)
jmp    122a <dpi_convert+0x10a>
movl   $0x9,-0x10(%rbp)
jmp    122a <dpi_convert+0x10a>
movl   $0xd,-0x10(%rbp)
jmp    122a <dpi_convert+0x10a>
mov    -0x4(%rbp),%esi
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
mov    $0x190,%ecx
cltd
idiv   %ecx
imul   $0x11,%eax,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    125c <dpi_convert+0x13c>
mov    -0x4(%rbp),%esi
lea    0xdb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dpi_convert>:
push   %rax
mov    %edi,%esi
lea    -0xc8(%rsi),%eax
cmp    $0x157c,%eax
ja     11ae <dpi_convert+0x8e>
movslq %esi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
mov    %esi,%ecx
sub    %eax,%ecx
jne    11ae <dpi_convert+0x8e>
movzwl %si,%eax
shr    $0x4,%eax
imul   $0xa3e,%eax,%eax
shr    $0x10,%eax
imul   $0x190,%eax,%ecx
mov    %esi,%edx
sub    %ecx,%edx
movzwl %dx,%ecx
cmp    $0xc7,%ecx
jg     1184 <dpi_convert+0x64>
test   %ecx,%ecx
je     11a0 <dpi_convert+0x80>
cmp    $0x64,%ecx
jne    11ae <dpi_convert+0x8e>
mov    $0x4,%ecx
jmp    11a0 <dpi_convert+0x80>
cmp    $0xc8,%ecx
je     119b <dpi_convert+0x7b>
cmp    $0x12c,%ecx
jne    11ae <dpi_convert+0x8e>
mov    $0xd,%ecx
jmp    11a0 <dpi_convert+0x80>
mov    $0x9,%ecx
movzwl %ax,%edx
mov    %edx,%eax
shl    $0x4,%eax
add    %edx,%eax
add    %ecx,%eax
pop    %rcx
ret
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"%i is not a valid DPI value\00"
define i32 @dpi_convert(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp sle i32 200, %9
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp sle i32 %12, 5700
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = load i32, i32* %2
%16 = srem i32 %15, 100
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i32, i32* %2
%20 = srem i32 %19, 400
store i32 %20, i32* %4
store i32 0, i32* %5
%21 = load i32, i32* %4
switch i32 %21, label %26 [
i32 0, label %22
i32 100, label %23
i32 200, label %24
i32 300, label %25
]
22: ; preds = %18
store i32 0, i32* %5
br label %30
23: ; preds = %18
store i32 4, i32* %5
br label %30
24: ; preds = %18
store i32 9, i32* %5
br label %30
25: ; preds = %18
store i32 13, i32* %5
br label %30
26: ; preds = %18
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %25, %24, %23, %22
%31 = load i32, i32* %2
%32 = sdiv i32 %31, 400
%33 = mul nsw i32 %32, 17
%34 = load i32, i32* %5
%35 = add nsw i32 %33, %34
store i32 %35, i32* %3
br label %40
36: ; preds = %14, %11, %8, %1
%37 = load i32, i32* %2
%38 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [28 x i8] c"%i is not a valid DPI value\00"
define i32 @dpi_convert(i32 %0) {
%2 = add i32 %0, -200
%3 = icmp ult i32 %2, 5501
%4 = srem i32 %0, 100
%5 = icmp eq i32 %4, 0
%6 = and i1 %3, %5
br i1 %6, label %7, label %23
7: ; preds = %1
%8 = trunc i32 %0 to i16
%9 = urem i16 %8, 400
%10 = udiv i16 %8, 400
%11 = zext i16 %9 to i32
switch i32 %11, label %15 [
i32 0, label %18
i32 100, label %12
i32 200, label %13
i32 300, label %14
]
12: ; preds = %7
br label %18
13: ; preds = %7
br label %18
14: ; preds = %7
br label %18
15: ; preds = %7
%16 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %7, %14, %13, %12
%19 = phi i32 [ 13, %14 ], [ 9, %13 ], [ 4, %12 ], [ %11, %7 ]
%20 = mul nuw nsw i16 %10, 17
%21 = zext i16 %20 to i32
%22 = add nuw nsw i32 %19, %21
ret i32 %22
23: ; preds = %1
%24 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %0)
%25 = tail call i32 @exit(i32 1)
unreachable
}