#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 */
int /*<<< orphan*/ sprintf(char *, char *, int);
int putoct(char *to, long val) {
  char *c = to;
  int tmp = val & 0xFF;
  if ((val >>= 8))
    c += putoct(c, val);
  sprintf(c, "\\%03o", tmp);
  return (c - to) + 4;
}


x86 assembly (clang, -O0):
<putoct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
and    $0xff,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
sar    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1178 <putoct+0x58>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <putoct@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe7a(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x4,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putoct>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdi,%rbx
cmp    $0x100,%rsi
jb     114c <putoct+0x2c>
mov    %r15,%rsi
sar    $0x8,%rsi
mov    %r14,%rdi
call   1030 <putoct@plt>
movslq %eax,%rbx
add    %r14,%rbx
movzbl %r15b,%edx
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
sub    %r14d,%ebx
add    $0x4,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"\\%03o\00"
define i32 @putoct(i8* %0, i64 %1) {
%3 = icmp ult i64 %1, 256
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = ashr i64 %1, 8
%6 = tail call i32 @putoct(i8* %0, i64 %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %4, %2
%10 = phi i8* [ %8, %4 ], [ %0, %2 ]
%11 = trunc i64 %1 to i32
%12 = and i32 %11, 255
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = ptrtoint i8* %10 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = add i32 %17, 4
ret i32 %18
}