char *pr_vertical(value, pos, neg)
int value;
char *pos;
char *neg;
{
  static char buf[256];
  register char *p = buf;
  char *direction;
  int meters, centimeters;
  unsigned int altitude;
  unsigned int reference;
  altitude = value;
  reference = 100000 * 100;
  if (altitude < reference) {
    direction = neg;
    altitude = reference - altitude;
  } else {
    direction = pos;
    altitude = altitude - reference;
  }
  centimeters = altitude % 100;
  altitude /= 100;
  meters = altitude;
  (void)sprintf(p, "%s%d", direction, meters);
  p += (int)strlen(p);
  if (centimeters > 0)
    (void)sprintf(p, ".%02d", centimeters);
  return (buf);
}


x86 assembly (clang, -O0):
<pr_vertical>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0x2f06(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x989680,-0x38(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jae    116d <pr_vertical+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    117e <pr_vertical+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
sub    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x64,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    11f3 <pr_vertical+0xd3>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2e46(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pr_vertical>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    -0x989680(%rbx),%eax
neg    %eax
sub    $0x989680,%ebx
cmovae %rsi,%rdx
cmovb  %eax,%ebx
imul   $0x51eb851f,%rbx,%rcx
shr    $0x25,%rcx
imul   $0x64,%ecx,%ebp
lea    0x2ef0(%rip),%r14
lea    0xea9(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
sub    %ebp,%ebx
je     1183 <pr_vertical+0x63>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
lea    0xe8b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2eb6(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@pr_vertical.buf = internal global [256 x i8] zeroinitializer
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [6 x i8] c".%02d\00"
define i8* @pr_vertical(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 0), i8** %7
%13 = load i32, i32* %4
store i32 %13, i32* %11
store i32 10000000, i32* %12
%14 = load i32, i32* %11
%15 = load i32, i32* %12
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load i8*, i8** %6
store i8* %18, i8** %8
%19 = load i32, i32* %12
%20 = load i32, i32* %11
%21 = sub i32 %19, %20
store i32 %21, i32* %11
br label %27
22: ; preds = %3
%23 = load i8*, i8** %5
store i8* %23, i8** %8
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = sub i32 %24, %25
store i32 %26, i32* %11
br label %27
27: ; preds = %22, %17
%28 = load i32, i32* %11
%29 = urem i32 %28, 100
store i32 %29, i32* %10
%30 = load i32, i32* %11
%31 = udiv i32 %30, 100
store i32 %31, i32* %11
%32 = load i32, i32* %11
store i32 %32, i32* %9
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %34, i32 %35)
%37 = load i8*, i8** %7
%38 = call i64 @strlen(i8* %37)
%39 = trunc i64 %38 to i32
%40 = load i8*, i8** %7
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %7
%43 = load i32, i32* %10
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %27
%46 = load i8*, i8** %7
%47 = load i32, i32* %10
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %27
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@pr_vertical.buf = internal global [256 x i8] zeroinitializer
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [6 x i8] c".%02d\00"
define i8* @pr_vertical(i32 %0, i8* %1, i8* %2) {
%4 = icmp ult i32 %0, 10000000
%5 = sub i32 10000000, %0
%6 = add i32 %0, -10000000
%7 = select i1 %4, i8* %2, i8* %1
%8 = select i1 %4, i32 %5, i32 %6
%9 = urem i32 %8, 100
%10 = udiv i32 %8, 100
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %10)
%12 = icmp eq i32 %9, 0
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 0))
%15 = shl i64 %14, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds [256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 %16
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %19
19: ; preds = %13, %3
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @pr_vertical.buf, i64 0, i64 0)
}