#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 */
long get_num(char *, char *);
int /*<<< orphan*/ halt(char *, char *);
char *long2str(char *, long);
char *macmod(char *arg) {
  long a, b;
  b = get_num("mod", arg);
  if (b == 0)
    halt("Function '%s': division by 0.", "mod");
  a = get_num("mod", arg);
  return (long2str(arg, a % b));
}


x86 assembly (clang, -O0):
<macmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   1030 <get_num@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116e <macmod+0x3e>
lea    0xea2(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1050 <halt@plt>
mov    -0x8(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1030 <get_num@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,%rsi
call   1040 <long2str@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<macmod>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
mov    %r14,%rsi
call   1030 <get_num@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1161 <macmod+0x31>
lea    0xeaf(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1050 <halt@plt>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
call   1030 <get_num@plt>
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     1183 <macmod+0x53>
cqto
idiv   %rbx
jmp    1187 <macmod+0x57>
xor    %edx,%edx
div    %ebx
mov    %r14,%rdi
mov    %rdx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <long2str@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"mod\00"
@.str.1 = [30 x i8] c"Function '%s': division by 0.\00"
define i8* @macmod(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @get_num(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @halt(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i8*, i8** %2
%13 = call i64 @get_num(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
store i64 %13, i64* %3
%14 = load i8*, i8** %2
%15 = load i64, i64* %3
%16 = load i64, i64* %4
%17 = srem i64 %15, %16
%18 = call i8* @long2str(i8* %14, i64 %17)
ret i8* %18
}

LLVM IR (-O2):
@.str = [4 x i8] c"mod\00"
@.str.1 = [30 x i8] c"Function '%s': division by 0.\00"
define i8* @macmod(i8* %0) {
%2 = tail call i64 @get_num(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @halt(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i64 @get_num(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = srem i64 %7, %2
%9 = tail call i8* @long2str(i8* %0, i64 %8)
ret i8* %9
}