#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 */
struct tm {
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ tm_decrement_minute(struct tm *, int);
int /*<<< orphan*/ tm_increment_second(struct tm *, int const);
struct tm *tm_decrement_second(struct tm *changing_tm, const int quantity) {
  static const int secs_in_min = 60;
  if (quantity < 0) {
    tm_increment_second(changing_tm, -quantity);
  } else {
    int num_secs = quantity;
    if (num_secs >= secs_in_min || num_secs > changing_tm->tm_sec) {
      int num_mins = quantity / secs_in_min;
      num_secs -= num_mins * secs_in_min;
      if (num_secs > changing_tm->tm_sec) {
        ++num_mins;
        num_secs -= changing_tm->tm_sec;
        changing_tm->tm_sec = secs_in_min;
      }
      tm_decrement_minute(changing_tm, num_mins);
    }
    changing_tm->tm_sec -= num_secs;
  }
  return changing_tm;
}


x86 assembly (clang, -O0):
<tm_decrement_second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114c <tm_decrement_second+0x2c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
sub    -0xc(%rbp),%esi
call   1030 <tm_increment_second@plt>
jmp    11ce <tm_decrement_second+0xae>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3c,-0x10(%rbp)
jge    116b <tm_decrement_second+0x4b>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jle    11c1 <tm_decrement_second+0xa1>
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
imul   $0x3c,-0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jle    11b5 <tm_decrement_second+0x95>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x3c,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <tm_decrement_minute@plt>
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_decrement_second>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
js     115c <tm_decrement_second+0x3c>
mov    (%rbx),%eax
cmp    $0x3b,%ebp
ja     1137 <tm_decrement_second+0x17>
cmp    %ebp,%eax
jge    1176 <tm_decrement_second+0x56>
mov    %ebp,%ecx
mov    $0x88888889,%esi
imul   %rcx,%rsi
shr    $0x25,%rsi
imul   $0xffffffc4,%esi,%ecx
add    %ebp,%ecx
mov    %ecx,%ebp
sub    %eax,%ebp
jle    116a <tm_decrement_second+0x4a>
add    $0x1,%esi
movl   $0x3c,(%rbx)
jmp    116c <tm_decrement_second+0x4c>
neg    %ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <tm_increment_second@plt>
jmp    117a <tm_decrement_second+0x5a>
mov    %ecx,%ebp
mov    %rbx,%rdi
call   1040 <tm_decrement_minute@plt>
mov    (%rbx),%eax
sub    %ebp,%eax
mov    %eax,(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@tm_decrement_second.secs_in_min = internal constant i32 60
define %struct.tm* @tm_decrement_second(%struct.tm* %0, i32 %1) {
%3 = alloca %struct.tm*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.tm* %0, %struct.tm** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load %struct.tm*, %struct.tm** %3
%11 = load i32, i32* %4
%12 = sub nsw i32 0, %11
%13 = call i32 @tm_increment_second(%struct.tm* %10, i32 %12)
br label %56
14: ; preds = %2
%15 = load i32, i32* %4
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 60
br i1 %17, label %24, label %18
18: ; preds = %14
%19 = load i32, i32* %5
%20 = load %struct.tm*, %struct.tm** %3
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = icmp sgt i32 %19, %22
br i1 %23, label %24, label %50
24: ; preds = %18, %14
%25 = load i32, i32* %4
%26 = sdiv i32 %25, 60
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = mul nsw i32 %27, 60
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, %28
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = load %struct.tm*, %struct.tm** %3
%33 = getelementptr inbounds %struct.tm, %struct.tm* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = icmp sgt i32 %31, %34
br i1 %35, label %36, label %46
36: ; preds = %24
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = load %struct.tm*, %struct.tm** %3
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* %5
%43 = sub nsw i32 %42, %41
store i32 %43, i32* %5
%44 = load %struct.tm*, %struct.tm** %3
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 0
store i32 60, i32* %45
br label %46
46: ; preds = %36, %24
%47 = load %struct.tm*, %struct.tm** %3
%48 = load i32, i32* %6
%49 = call i32 @tm_decrement_minute(%struct.tm* %47, i32 %48)
br label %50
50: ; preds = %46, %18
%51 = load i32, i32* %5
%52 = load %struct.tm*, %struct.tm** %3
%53 = getelementptr inbounds %struct.tm, %struct.tm* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = sub nsw i32 %54, %51
store i32 %55, i32* %53
br label %56
56: ; preds = %50, %9
%57 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %57
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define %struct.tm* @tm_decrement_second(%struct.tm* returned %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sub nsw i32 0, %1
%6 = tail call i32 @tm_increment_second(%struct.tm* %0, i32 %5)
br label %32
7: ; preds = %2
%8 = icmp ugt i32 %1, 59
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, %1
%12 = select i1 %8, i1 true, i1 %11
br i1 %12, label %13, label %27
13: ; preds = %7
%14 = udiv i32 %1, 60
%15 = mul nsw i32 %14, -60
%16 = add nsw i32 %15, %1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%18 = icmp sgt i32 %16, %10
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = add nuw nsw i32 %14, 1
%21 = sub nsw i32 %16, %10
store i32 60, i32* %17
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ %21, %19 ], [ %16, %13 ]
%24 = phi i32 [ %20, %19 ], [ %14, %13 ]
%25 = tail call i32 @tm_decrement_minute(%struct.tm* %0, i32 %24)
%26 = load i32, i32* %17
br label %27
27: ; preds = %7, %22
%28 = phi i32 [ %26, %22 ], [ %10, %7 ]
%29 = phi i32 [ %23, %22 ], [ %1, %7 ]
%30 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%31 = sub nsw i32 %28, %29
store i32 %31, i32* %30
br label %32
32: ; preds = %27, %4
ret %struct.tm* %0
}