#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*/ cat3(int /*<<< orphan*/, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int /*<<< orphan*/ int2str(int);
int /*<<< orphan*/ newstr(char *);
int /*<<< orphan*/ runtime_error(int, int /*<<< orphan*/);
int int_div(int line, int a, int b) {
  if (b == 0) {
    runtime_error(line, cat3(newstr("Unable to divide "), int2str(a),
                             newstr(" by zero!")));
  }
  return a / b;
}


x86 assembly (clang, -O0):
<int_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    119e <int_div+0x5e>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    0xe98(%rip),%rdi
call   1060 <newstr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <int2str@plt>
mov    %eax,-0x14(%rbp)
lea    0xe90(%rip),%rdi
call   1060 <newstr@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    %eax,%edx
call   1040 <cat3@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
call   1050 <runtime_error@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_div>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
test   %edx,%edx
jne    118f <int_div+0x4f>
mov    %edi,%r14d
lea    0xea6(%rip),%rdi
call   1060 <newstr@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1030 <int2str@plt>
mov    %eax,%r12d
lea    0xe9f(%rip),%rdi
call   1060 <newstr@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %eax,%edx
call   1040 <cat3@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1050 <runtime_error@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Unable to divide \00"
@.str.1 = [10 x i8] c" by zero!\00"
define i32 @int_div(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load i32, i32* %4
%11 = call i32 @newstr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %5
%13 = call i32 @int2str(i32 %12)
%14 = call i32 @newstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @cat3(i32 %11, i32 %13, i32 %14)
%16 = call i32 @runtime_error(i32 %10, i32 %15)
br label %17
17: ; preds = %9, %3
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sdiv i32 %18, %19
ret i32 %20
}

LLVM IR (-O2):
@.str = [18 x i8] c"Unable to divide \00"
@.str.1 = [10 x i8] c" by zero!\00"
define i32 @int_div(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %11
5: ; preds = %3
%6 = tail call i32 @newstr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @int2str(i32 %1)
%8 = tail call i32 @newstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @cat3(i32 %6, i32 %7, i32 %8)
%10 = tail call i32 @runtime_error(i32 %0, i32 %9)
br label %11
11: ; preds = %5, %3
%12 = sdiv i32 %1, %2
ret i32 %12
}