#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 */
long atol(char *);
int sprintf(char *, char *, long);
int strlen(char *);
int middle_minus_one(char *s1) {
  int full = strlen(s1);
  int half = (strlen(s1) + 1) / 2;
  int count = full - half;
  long minus = 1;
  while (count--)
    minus *= 10;
  long n1 = atol(s1) - minus;
  return sprintf(s1, "%ld", n1);
}


x86 assembly (clang, -O0):
<middle_minus_one>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1192 <middle_minus_one+0x62>
imul   $0xa,-0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1170 <middle_minus_one+0x40>
mov    -0x8(%rbp),%rdi
call   1040 <atol@plt>
sub    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<middle_minus_one>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
add    $0x1,%eax
sar    %eax
mov    %ebx,%ecx
sub    %eax,%ecx
je     1174 <middle_minus_one+0x44>
neg    %eax
lea    (%rbx,%rax,1),%edx
add    $0xffffffff,%edx
mov    %ecx,%eax
and    $0x7,%eax
cmp    $0x7,%edx
jae    117b <middle_minus_one+0x4b>
mov    $0x1,%ebx
jmp    119c <middle_minus_one+0x6c>
mov    $0x1,%ebx
jmp    11ac <middle_minus_one+0x7c>
and    $0xfffffff8,%ecx
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
imul   $0x5f5e100,%rbx,%rbx
add    $0xfffffff8,%ecx
jne    1190 <middle_minus_one+0x60>
test   %eax,%eax
je     11ac <middle_minus_one+0x7c>
add    %rbx,%rbx
lea    (%rbx,%rbx,4),%rbx
add    $0xffffffff,%eax
jne    11a0 <middle_minus_one+0x70>
mov    %r14,%rdi
call   1040 <atol@plt>
sub    %rbx,%rax
lea    0xe42(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define i32 @middle_minus_one(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = sdiv i32 %12, 2
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %5
store i64 1, i64* %6
br label %17
17: ; preds = %21, %1
%18 = load i32, i32* %5
%19 = add nsw i32 %18, -1
store i32 %19, i32* %5
%20 = icmp ne i32 %18, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* %6
%23 = mul nsw i64 %22, 10
store i64 %23, i64* %6
br label %17
24: ; preds = %17
%25 = load i8*, i8** %2
%26 = call i64 @atol(i8* %25)
%27 = load i64, i64* %6
%28 = sub nsw i64 %26, %27
store i64 %28, i64* %7
%29 = load i8*, i8** %2
%30 = load i64, i64* %7
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %30)
ret i32 %31
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @middle_minus_one(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = sdiv i32 %4, -2
%6 = add i32 %5, %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %1
%9 = add i32 %2, %5
%10 = add i32 %9, -1
%11 = and i32 %6, 7
%12 = icmp ult i32 %10, 7
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = and i32 %6, -8
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 1, %13 ], [ %18, %15 ]
%17 = phi i32 [ 0, %13 ], [ %19, %15 ]
%18 = mul i64 %16, 100000000
%19 = add i32 %17, 8
%20 = icmp eq i32 %19, %14
br i1 %20, label %21, label %15
21: ; preds = %15, %8
%22 = phi i64 [ undef, %8 ], [ %18, %15 ]
%23 = phi i64 [ 1, %8 ], [ %18, %15 ]
%24 = icmp eq i32 %11, 0
br i1 %24, label %31, label %25
25: ; preds = %21, %25
%26 = phi i64 [ %28, %25 ], [ %23, %21 ]
%27 = phi i32 [ %29, %25 ], [ 0, %21 ]
%28 = mul nsw i64 %26, 10
%29 = add i32 %27, 1
%30 = icmp eq i32 %29, %11
br i1 %30, label %31, label %25
31: ; preds = %21, %25, %1
%32 = phi i64 [ 1, %1 ], [ %22, %21 ], [ %28, %25 ]
%33 = tail call i64 @atol(i8* %0)
%34 = sub nsw i64 %33, %32
%35 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %34)
ret i32 %35
}