#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 */
typedef int time_t;
struct tm {
  scalar_t__ tm_yday;
  scalar_t__ tm_wday;
  scalar_t__ tm_mon;
  scalar_t__ tm_mday;
  scalar_t__ tm_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
};
struct timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ localtime_r(int *, struct tm *);
int mktime(struct tm *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int);
time_t cm11a_decodebattery(char *buf) {
  time_t t;
  struct timeval tv;
  struct tm tm;
  int battery, rev, h, m, s, jday, day, hcode, addmon, statmon, statdim;
  int i;
  gettimeofday(&tv, 0);
  t = (time_t)tv.tv_sec;
  localtime_r(&t, &tm);
  tm.tm_sec = 0;
  tm.tm_min = 0;
  tm.tm_hour = 0;
  tm.tm_mday = 0;
  tm.tm_mon = 0;
  tm.tm_wday = 0;
  tm.tm_yday = 0;
  t = mktime(&tm);
  battery = ((buf[0] << 8) | (unsigned int)buf[0]);
  if (battery == 0xffff)
    battery = 0;
  s = buf[2] & 0xff;
  m = (buf[3] & 0xff) % 60;
  h = ((buf[4] & 0xff) * 2) + ((buf[3] & 0xff) / 60);
  jday = buf[5] + (((buf[6] & 0x80) >> 7) * 256);
  t += (time_t)(jday + 1) * 24 * 60 * 60;
  t += (time_t)h * 60 * 60;
  t += (time_t)m * 60;
  t += (time_t)s;
  day = buf[6] & 0x7f;
  hcode = (buf[7] & 0xf0) >> 4;
  rev = buf[7] & 0x0f;
  addmon = buf[8] | (buf[9] << 8);
  statmon = buf[10] | (buf[11] << 8);
  statdim = buf[12] | (buf[13] << 8);
  syslog(LOG_INFO, "cm11a version %d found\n", rev);
  return t;
}


x86 assembly (clang, -O0):
<cm11a_decodebattery>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1030 <localtime_r@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x54(%rbp)
cmpl   $0xffff,-0x54(%rbp)
jne    11dc <cm11a_decodebattery+0x9c>
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
and    $0xff,%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x60(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x4(%rax),%eax
and    $0xff,%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%eax
and    $0xff,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x5(%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl 0x6(%rcx),%ecx
and    $0x80,%ecx
sar    $0x7,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
imul   $0x18,%eax,%eax
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0x3c,-0x5c(%rbp),%eax
imul   $0x3c,%eax,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0x3c,-0x60(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x64(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x6(%rax),%eax
and    $0x7f,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x7(%rax),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %eax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x7(%rax),%eax
and    $0xf,%eax
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x8(%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl 0x9(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0xa(%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl 0xb(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x78(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0xc(%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl 0xd(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x7c(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%edx
lea    0xce4(%rip),%rsi
call   1050 <syslog@plt>
mov    -0xc(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm11a_decodebattery>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1030 <localtime_r@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
mov    %r14,%rdi
call   1060 <mktime@plt>
movzbl 0x2(%rbx),%ecx
movzbl 0x3(%rbx),%edx
imul   $0x89,%edx,%esi
shr    $0xd,%esi
imul   $0x3c,%esi,%edi
sub    %dil,%dl
movzbl %dl,%r8d
movzbl 0x4(%rbx),%edi
lea    (%rsi,%rdi,2),%esi
movsbl 0x5(%rbx),%edi
movzbl 0x6(%rbx),%edx
and    $0x80,%edx
lea    (%rdi,%rdx,2),%edx
imul   $0x15180,%edx,%edx
imul   $0xe10,%esi,%esi
imul   $0x3c,%r8d,%edi
add    %eax,%ecx
add    %edi,%ecx
add    %esi,%ecx
lea    (%rdx,%rcx,1),%eax
add    $0x15180,%eax
mov    %eax,0x4(%rsp)
movzbl 0x7(%rbx),%edx
and    $0xf,%edx
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <syslog@plt>
mov    0x4(%rsp),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.tm = type { i64, i64, i64, i64, i64, i64, i64 }
@LOG_INFO = global i32 0
@.str = [24 x i8] c"cm11a version %d found\0A\00"
define i32 @cm11a_decodebattery(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.tm
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %2
%18 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
store i32 %21, i32* %3
%22 = call i32 @localtime_r(i32* %3, %struct.tm* %5)
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 6
store i64 0, i64* %23
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
store i64 0, i64* %24
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
store i64 0, i64* %25
%26 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
store i64 0, i64* %26
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
store i64 0, i64* %27
%28 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i64 0, i64* %29
%30 = call i32 @mktime(%struct.tm* %5)
store i32 %30, i32* %3
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = shl i32 %34, 8
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = or i32 %35, %39
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, 65535
br i1 %42, label %43, label %44
43: ; preds = %1
store i32 0, i32* %6
br label %44
44: ; preds = %43, %1
%45 = load i8*, i8** %2
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = and i32 %48, 255
store i32 %49, i32* %10
%50 = load i8*, i8** %2
%51 = getelementptr inbounds i8, i8* %50, i64 3
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = and i32 %53, 255
%55 = srem i32 %54, 60
store i32 %55, i32* %9
%56 = load i8*, i8** %2
%57 = getelementptr inbounds i8, i8* %56, i64 4
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = and i32 %59, 255
%61 = mul nsw i32 %60, 2
%62 = load i8*, i8** %2
%63 = getelementptr inbounds i8, i8* %62, i64 3
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = and i32 %65, 255
%67 = sdiv i32 %66, 60
%68 = add nsw i32 %61, %67
store i32 %68, i32* %8
%69 = load i8*, i8** %2
%70 = getelementptr inbounds i8, i8* %69, i64 5
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = load i8*, i8** %2
%74 = getelementptr inbounds i8, i8* %73, i64 6
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = and i32 %76, 128
%78 = ashr i32 %77, 7
%79 = mul nsw i32 %78, 256
%80 = add nsw i32 %72, %79
store i32 %80, i32* %11
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
%83 = mul nsw i32 %82, 24
%84 = mul nsw i32 %83, 60
%85 = mul nsw i32 %84, 60
%86 = load i32, i32* %3
%87 = add nsw i32 %86, %85
store i32 %87, i32* %3
%88 = load i32, i32* %8
%89 = mul nsw i32 %88, 60
%90 = mul nsw i32 %89, 60
%91 = load i32, i32* %3
%92 = add nsw i32 %91, %90
store i32 %92, i32* %3
%93 = load i32, i32* %9
%94 = mul nsw i32 %93, 60
%95 = load i32, i32* %3
%96 = add nsw i32 %95, %94
store i32 %96, i32* %3
%97 = load i32, i32* %10
%98 = load i32, i32* %3
%99 = add nsw i32 %98, %97
store i32 %99, i32* %3
%100 = load i8*, i8** %2
%101 = getelementptr inbounds i8, i8* %100, i64 6
%102 = load i8, i8* %101
%103 = sext i8 %102 to i32
%104 = and i32 %103, 127
store i32 %104, i32* %12
%105 = load i8*, i8** %2
%106 = getelementptr inbounds i8, i8* %105, i64 7
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = and i32 %108, 240
%110 = ashr i32 %109, 4
store i32 %110, i32* %13
%111 = load i8*, i8** %2
%112 = getelementptr inbounds i8, i8* %111, i64 7
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = and i32 %114, 15
store i32 %115, i32* %7
%116 = load i8*, i8** %2
%117 = getelementptr inbounds i8, i8* %116, i64 8
%118 = load i8, i8* %117
%119 = sext i8 %118 to i32
%120 = load i8*, i8** %2
%121 = getelementptr inbounds i8, i8* %120, i64 9
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = shl i32 %123, 8
%125 = or i32 %119, %124
store i32 %125, i32* %14
%126 = load i8*, i8** %2
%127 = getelementptr inbounds i8, i8* %126, i64 10
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = load i8*, i8** %2
%131 = getelementptr inbounds i8, i8* %130, i64 11
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = shl i32 %133, 8
%135 = or i32 %129, %134
store i32 %135, i32* %15
%136 = load i8*, i8** %2
%137 = getelementptr inbounds i8, i8* %136, i64 12
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = load i8*, i8** %2
%141 = getelementptr inbounds i8, i8* %140, i64 13
%142 = load i8, i8* %141
%143 = sext i8 %142 to i32
%144 = shl i32 %143, 8
%145 = or i32 %139, %144
store i32 %145, i32* %16
%146 = load i32, i32* @LOG_INFO
%147 = load i32, i32* %7
%148 = call i32 @syslog(i32 %146, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %147)
%149 = load i32, i32* %3
ret i32 %149
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.tm = type { i64, i64, i64, i64, i64, i64, i64 }
@LOG_INFO = global i32 0
@.str = [24 x i8] c"cm11a version %d found\0A\00"
define i32 @cm11a_decodebattery(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = bitcast i32* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.tm* %4 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %2
%12 = call i32 @localtime_r(i32* %2, %struct.tm* %4)
%13 = bitcast %struct.tm* %4 to i8*
%14 = call i32 @mktime(%struct.tm* %4)
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = getelementptr inbounds i8, i8* %0, i64 3
%19 = load i8, i8* %18
%20 = urem i8 %19, 60
%21 = zext i8 %20 to i32
%22 = getelementptr inbounds i8, i8* %0, i64 4
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 1
%26 = udiv i8 %19, 60
%27 = zext i8 %26 to i32
%28 = add nuw nsw i32 %25, %27
%29 = getelementptr inbounds i8, i8* %0, i64 5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = getelementptr inbounds i8, i8* %0, i64 6
%33 = load i8, i8* %32
%34 = lshr i8 %33, 7
%35 = zext i8 %34 to i32
%36 = shl nuw nsw i32 %35, 8
%37 = add nsw i32 %36, %31
%38 = mul nsw i32 %37, 86400
%39 = mul nuw nsw i32 %28, 3600
%40 = mul nuw nsw i32 %21, 60
%41 = add i32 %14, 86400
%42 = add i32 %41, %17
%43 = add i32 %42, %40
%44 = add i32 %43, %39
%45 = add i32 %44, %38
store i32 %45, i32* %2
%46 = getelementptr inbounds i8, i8* %0, i64 7
%47 = load i8, i8* %46
%48 = and i8 %47, 15
%49 = zext i8 %48 to i32
%50 = load i32, i32* @LOG_INFO
%51 = call i32 @syslog(i32 %50, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %49)
%52 = load i32, i32* %2
ret i32 %52
}