#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*/ printf(char *, int, ...);
int read_reg(int);
int /*<<< orphan*/ start_movdbz_program();
int /*<<< orphan*/ write_reg(int, int);
void add(int a, int b) {
  write_reg(0, a);
  write_reg(1, b);
  printf("Calculate saturated r0 + r1 where r0 = %d and r1 = %d\n", read_reg(0),
         read_reg(1));
  start_movdbz_program();
  printf("Result: r3 = %d\n\n", read_reg(3));
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
xor    %edi,%edi
call   1040 <write_reg@plt>
mov    -0x8(%rbp),%esi
mov    $0x1,%edi
call   1040 <write_reg@plt>
xor    %edi,%edi
call   1060 <read_reg@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
call   1060 <read_reg@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <start_movdbz_program@plt>
mov    $0x3,%edi
call   1060 <read_reg@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbx
mov    %esi,%ebx
mov    %edi,%esi
xor    %edi,%edi
call   1040 <write_reg@plt>
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <write_reg@plt>
xor    %edi,%edi
call   1060 <read_reg@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1060 <read_reg@plt>
lea    0xe8e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <start_movdbz_program@plt>
mov    $0x3,%edi
call   1060 <read_reg@plt>
lea    0xea2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [55 x i8] c"Calculate saturated r0 + r1 where r0 = %d and r1 = %d\0A\00"
@.str.1 = [18 x i8] c"Result: r3 = %d\0A\0A\00"
define void @add(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = call i32 @write_reg(i32 0, i32 %5)
%7 = load i32, i32* %4
%8 = call i32 @write_reg(i32 1, i32 %7)
%9 = call i32 @read_reg(i32 0)
%10 = call i32 @read_reg(i32 1)
%11 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = call i32 (...) @start_movdbz_program()
%13 = call i32 @read_reg(i32 3)
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret void
}

LLVM IR (-O2):
@.str = [55 x i8] c"Calculate saturated r0 + r1 where r0 = %d and r1 = %d\0A\00"
@.str.1 = [18 x i8] c"Result: r3 = %d\0A\0A\00"
define void @add(i32 %0, i32 %1) {
%3 = tail call i32 @write_reg(i32 0, i32 %0)
%4 = tail call i32 @write_reg(i32 1, i32 %1)
%5 = tail call i32 @read_reg(i32 0)
%6 = tail call i32 @read_reg(i32 1)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 (...) @start_movdbz_program()
%9 = tail call i32 @read_reg(i32 3)
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret void
}