#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 */
typedef int __uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, int, int);
__uint32_t check_div(char *name, __uint32_t val, __uint32_t div) {
  if (val < div || 0 == val || (val % div)) {
    printf("New Param %s (%d) zero, not large enough, or not evenly divisible "
           "by %d\n",
           name, val, div);
    return 0;
  }
  return val / div;
}


x86 assembly (clang, -O0):
<check_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1149 <check_div+0x39>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
je     1149 <check_div+0x39>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
cmp    $0x0,%edx
je     116b <check_div+0x5b>
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1175 <check_div+0x65>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_div>:
mov    %edx,%r8d
mov    %esi,%ecx
mov    %rdi,%rsi
test   %ecx,%ecx
je     112b <check_div+0x1b>
cmp    %r8d,%ecx
jl     112b <check_div+0x1b>
mov    %ecx,%eax
cltd
idiv   %r8d
test   %edx,%edx
je     1143 <check_div+0x33>
push   %rax
lea    0xecd(%rip),%rdi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [73 x i8] c"New Param %s (%d) zero, not large enough, or not evenly divisible by %d\0A\00"
define i32 @check_div(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = load i32, i32* %7
%10 = icmp slt i32 %8, %9
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp eq i32 0, %12
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i32, i32* %7
%17 = srem i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14, %11, %3
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21, i32 %22)
store i32 0, i32* %4
br label %28
24: ; preds = %14
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = sdiv i32 %25, %26
store i32 %27, i32* %4
br label %28
28: ; preds = %24, %19
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [73 x i8] c"New Param %s (%d) zero, not large enough, or not evenly divisible by %d\0A\00"
define i32 @check_div(i8* %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
%5 = icmp eq i32 %1, 0
%6 = or i1 %5, %4
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = srem i32 %1, %2
%9 = sdiv i32 %1, %2
%10 = icmp eq i32 %8, 0
br i1 %10, label %13, label %11
11: ; preds = %7, %3
%12 = tail call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ 0, %11 ], [ %9, %7 ]
ret i32 %14
}