#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 i2c_read_register(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
long calculate_total_frame_time(void) {
  long row_time, total_frame_time;
  row_time = ((i2c_read_register("/dev/i2c-0", 0x5D, 0x04) + 1) +
              (244 + i2c_read_register("/dev/i2c-0", 0x5D, 0x05) - 19));
  total_frame_time = (i2c_read_register("/dev/i2c-0", 0x5D, 0x03) + 1 +
                      i2c_read_register("/dev/i2c-0", 0x5D, 0x06) + 1) *
                     row_time;
  printf("************* Calculated Times Based on the actual Camera setting "
         "*************\n");
  printf("Master Clock = \t\t%d MHz \n", 48);
  printf("row_time = \t\t%d pixel clocks\ntotal_frame_time = \t%d pixel "
         "clocks\ntotal_frame_time = \t%d usec\n",
         row_time, total_frame_time, total_frame_time / 48);
  printf("*********************************************************************"
         "**********\n");
}


x86 assembly (clang, -O0):
<calculate_total_frame_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rdi
mov    $0x5d,%esi
mov    $0x4,%edx
call   1040 <i2c_read_register@plt>
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x5d,%esi
mov    $0x5,%edx
call   1040 <i2c_read_register@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    $0xf4,%ecx
sub    $0x13,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rdi
mov    $0x5d,%esi
mov    $0x3,%edx
call   1040 <i2c_read_register@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    0xe6d(%rip),%rdi
mov    $0x5d,%esi
mov    $0x6,%edx
call   1040 <i2c_read_register@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
imul   -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe90(%rip),%rdi
mov    $0x30,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x30,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_total_frame_time>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%r15
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x4,%edx
call   1050 <i2c_read_register@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x5,%edx
call   1050 <i2c_read_register@plt>
add    %ebx,%eax
add    $0xe2,%eax
movslq %eax,%r14
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x3,%edx
call   1050 <i2c_read_register@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    $0x5d,%esi
mov    $0x6,%edx
call   1050 <i2c_read_register@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rbx
imul   %r14,%rbx
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
lea    0xe5a(%rip),%rdi
mov    $0x30,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x2aaaaaaaaaaaaaab,%rcx
aa aa 2a
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x3,%rdx
add    %rdx,%rcx
lea    0xe43(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-0\00"
@.str.1 = [81 x i8] c"************* Calculated Times Based on the actual Camera setting *************\0A\00"
@.str.2 = [26 x i8] c"Master Clock = \09\09%d MHz \0A\00"
@.str.3 = [94 x i8] c"row_time = \09\09%d pixel clocks\0Atotal_frame_time = \09%d pixel clocks\0Atotal_frame_time = \09%d usec\0A\00"
@.str.4 = [81 x i8] c"*******************************************************************************\0A\00"
define i64 @calculate_total_frame_time() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 4)
%5 = add nsw i32 %4, 1
%6 = call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 5)
%7 = add nsw i32 244, %6
%8 = sub nsw i32 %7, 19
%9 = add nsw i32 %5, %8
%10 = sext i32 %9 to i64
store i64 %10, i64* %2
%11 = call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 3)
%12 = add nsw i32 %11, 1
%13 = call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 6)
%14 = add nsw i32 %12, %13
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = load i64, i64* %2
%18 = mul nsw i64 %16, %17
store i64 %18, i64* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 48)
%21 = load i64, i64* %2
%22 = load i64, i64* %3
%23 = load i64, i64* %3
%24 = sdiv i64 %23, 48
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.3, i64 0, i64 0), i64 %21, i64 %22, i64 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.4, i64 0, i64 0))
%27 = load i64, i64* %1
ret i64 %27
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-0\00"
@.str.2 = [26 x i8] c"Master Clock = \09\09%d MHz \0A\00"
@.str.3 = [94 x i8] c"row_time = \09\09%d pixel clocks\0Atotal_frame_time = \09%d pixel clocks\0Atotal_frame_time = \09%d usec\0A\00"
@str = [80 x i8] c"************* Calculated Times Based on the actual Camera setting *************\00"
@str.5 = [80 x i8] c"*******************************************************************************\00"
define i64 @calculate_total_frame_time() {
%1 = tail call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 4)
%2 = tail call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 5)
%3 = add i32 %1, 226
%4 = add i32 %3, %2
%5 = sext i32 %4 to i64
%6 = tail call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 3)
%7 = tail call i32 @i2c_read_register(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 93, i32 6)
%8 = add i32 %6, 2
%9 = add i32 %8, %7
%10 = sext i32 %9 to i64
%11 = mul nsw i64 %10, %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 48)
%14 = sdiv i64 %11, 48
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([94 x i8], [94 x i8]* @.str.3, i64 0, i64 0), i64 %5, i64 %11, i64 %14)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str.5, i64 0, i64 0))
ret i64 undef
}