#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_smbus_write_i2c_block_data(int, int, int, unsigned char *);
int arduino_write_rtc(int client, unsigned long time, int reg, int nbytes) {
  unsigned char buf[4];
  int i;
  if (nbytes > 4) {
    return -1;
  }
  for (i = 0; i < nbytes; i++) {
    buf[i] = time & 0xff;
    time >>= 8;
  }
  return i2c_smbus_write_i2c_block_data(client, reg, nbytes, buf);
}


x86 assembly (clang, -O0):
<arduino_write_rtc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jle    113b <arduino_write_rtc+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <arduino_write_rtc+0x81>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    117c <arduino_write_rtc+0x6c>
mov    -0x10(%rbp),%rax
and    $0xff,%rax
mov    %al,%cl
movslq -0x20(%rbp),%rax
mov    %cl,-0x1c(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1142 <arduino_write_rtc+0x32>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x1c(%rbp),%rcx
call   1030 <i2c_smbus_write_i2c_block_data@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arduino_write_rtc>:
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jg     1166 <arduino_write_rtc+0x56>
push   %rbx
sub    $0x10,%rsp
test   %ecx,%ecx
jle    1150 <arduino_write_rtc+0x40>
mov    %rsi,%rbx
mov    %bl,0xc(%rsp)
cmp    $0x1,%ecx
je     1150 <arduino_write_rtc+0x40>
mov    %bh,0xd(%rsp)
cmp    $0x2,%ecx
je     1150 <arduino_write_rtc+0x40>
mov    %rbx,%rax
shr    $0x10,%rax
mov    %al,0xe(%rsp)
cmp    $0x3,%ecx
je     1150 <arduino_write_rtc+0x40>
shr    $0x18,%rbx
mov    %bl,0xf(%rsp)
lea    0xc(%rsp),%rax
mov    %edx,%esi
mov    %ecx,%edx
mov    %rax,%rcx
call   1030 <i2c_smbus_write_i2c_block_data@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @arduino_write_rtc(i32 %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca [4 x i8]
%11 = alloca i32
store i32 %0, i32* %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i32, i32* %9
%13 = icmp sgt i32 %12, 4
br i1 %13, label %14, label %15
14: ; preds = %4
store i32 -1, i32* %5
br label %38
15: ; preds = %4
store i32 0, i32* %11
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %11
%18 = load i32, i32* %9
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i64, i64* %7
%22 = and i64 %21, 255
%23 = trunc i64 %22 to i8
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 %25
store i8 %23, i8* %26
%27 = load i64, i64* %7
%28 = lshr i64 %27, 8
store i64 %28, i64* %7
br label %29
29: ; preds = %20
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %16
32: ; preds = %16
%33 = load i32, i32* %6
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%37 = call i32 @i2c_smbus_write_i2c_block_data(i32 %33, i32 %34, i32 %35, i8* %36)
store i32 %37, i32* %5
br label %38
38: ; preds = %32, %14
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
define i32 @arduino_write_rtc(i32 %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca [4 x i8]
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %3, 4
br i1 %7, label %30, label %8
8: ; preds = %4
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %28
10: ; preds = %8
%11 = trunc i64 %1 to i8
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
store i8 %11, i8* %12
%13 = icmp eq i32 %3, 1
br i1 %13, label %28, label %14
14: ; preds = %10
%15 = lshr i64 %1, 8
%16 = trunc i64 %15 to i8
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 %16, i8* %17
%18 = icmp eq i32 %3, 2
br i1 %18, label %28, label %19
19: ; preds = %14
%20 = lshr i64 %1, 16
%21 = trunc i64 %20 to i8
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 %21, i8* %22
%23 = icmp eq i32 %3, 3
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = lshr i64 %1, 24
%26 = trunc i64 %25 to i8
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
store i8 %26, i8* %27
br label %28
28: ; preds = %10, %14, %19, %24, %8
%29 = call i32 @i2c_smbus_write_i2c_block_data(i32 %0, i32 %2, i32 %3, i8* %6)
br label %30
30: ; preds = %4, %28
%31 = phi i32 [ %29, %28 ], [ -1, %4 ]
ret i32 %31
}