#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(char *);
char *str_dup(char *);
char *str_int(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
extern void str_dec(char **s) {
  char *buf = str_int(atoi(*s) - 1);
  if (strlen(buf) <= strlen(*s)) {
    strcpy(*s, buf);
    return;
  }
  free(*s);
  *s = str_dup(buf);
}


x86 assembly (clang, -O0):
<str_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,%rdi
sub    $0x1,%rdi
call   1060 <str_int@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jg     11c6 <str_dec+0x66>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11e5 <str_dec+0x85>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1080 <str_dup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_dec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rdi
call   1070 <atoi@plt>
lea    -0x1(%rax),%rdi
call   1060 <str_int@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    (%r14),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
cmp    %rax,%r12
jle    11b9 <str_dec+0x59>
call   1030 <free@plt>
mov    %r15,%rdi
call   1080 <str_dup@plt>
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
define void @str_dec(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = load i8*, i8** %4
%6 = call i64 @atoi(i8* %5)
%7 = sub nsw i64 %6, 1
%8 = call i8* @str_int(i64 %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = load i8**, i8*** %2
%12 = load i8*, i8** %11
%13 = call i64 @strlen(i8* %12)
%14 = icmp sle i64 %10, %13
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %17, i8* %18)
br label %27
20: ; preds = %1
%21 = load i8**, i8*** %2
%22 = load i8*, i8** %21
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %3
%25 = call i8* @str_dup(i8* %24)
%26 = load i8**, i8*** %2
store i8* %25, i8** %26
br label %27
27: ; preds = %20, %15
ret void
}

LLVM IR (-O2):
define void @str_dec(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i64 @atoi(i8* %2)
%4 = add nsw i64 %3, -1
%5 = tail call i8* @str_int(i64 %4)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = load i8*, i8** %0
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = icmp sgt i64 %6, %8
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @strcpy(i8* %7, i8* %5)
br label %15
12: ; preds = %1
%13 = tail call i32 @free(i8* %7)
%14 = tail call i8* @str_dup(i8* %5)
store i8* %14, i8** %0
br label %15
15: ; preds = %12, %10
ret void
}