#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*/ out_char(char);
int /*<<< orphan*/ out_string(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int out_args(char *mystr) {
  char *here;
  int strcount = 0;
  char tmpstr[5];
  for (here = mystr; *here; here++) {
    if (*here == '\\') {
      out_string("\\\\");
      strcount += 2;
    } else if (*here >= ' ' && *here <= '~') {
      out_char(*here);
      strcount++;
    } else {
      sprintf(tmpstr, "\\%03o", (unsigned char)*here);
      out_string(tmpstr);
      strcount += 4;
    }
  }
  return strcount;
}


x86 assembly (clang, -O0):
<out_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1200 <out_args+0xd0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1182 <out_args+0x52>
lea    0xe91(%rip),%rdi
call   1030 <out_string@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <out_args+0xba>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     11bc <out_args+0x8c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jg     11bc <out_args+0x8c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <out_char@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e5 <out_args+0xb5>
lea    -0x19(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xe38(%rip),%rsi
movzbl (%rax),%edx
call   1040 <sprintf@plt>
lea    -0x19(%rbp),%rdi
call   1030 <out_string@plt>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <out_args+0xba>
jmp    11ef <out_args+0xbf>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114b <out_args+0x1b>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<out_args>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xeb8(%rip),%r14
lea    0xeb4(%rip),%r15
lea    0xb(%rsp),%r12
jmp    1173 <out_args+0x43>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <out_string@plt>
mov    $0x2,%eax
add    %eax,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1160 <out_args+0x30>
test   %al,%al
je     11bf <out_args+0x8f>
lea    -0x7f(%rax),%ecx
cmp    $0xa1,%cl
jae    11b0 <out_args+0x80>
movzbl %al,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
mov    %r12,%rdi
call   1030 <out_string@plt>
mov    $0x4,%eax
jmp    116d <out_args+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1050 <out_char@plt>
mov    $0x1,%eax
jmp    116d <out_args+0x3d>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\\\\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define i32 @out_args(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [5 x i8]
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %47, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %50
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 92
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = call i32 @out_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 2
store i32 %19, i32* %4
br label %46
20: ; preds = %11
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 32
br i1 %24, label %25, label %36
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sle i32 %28, 126
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = call i32 @out_char(i8 signext %32)
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %45
36: ; preds = %25, %20
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%38 = load i8*, i8** %3
%39 = load i8, i8* %38
%40 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %39)
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%42 = call i32 @out_string(i8* %41)
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 4
store i32 %44, i32* %4
br label %45
45: ; preds = %36, %30
br label %46
46: ; preds = %45, %16
br label %47
47: ; preds = %46
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %3
br label %7
50: ; preds = %7
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\\\\00"
@.str.1 = [6 x i8] c"\\%03o\00"
define i32 @out_args(i8* nocapture %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %18, %1
%5 = phi i8* [ %0, %1 ], [ %21, %18 ]
%6 = phi i32 [ 0, %1 ], [ %20, %18 ]
%7 = load i8, i8* %5
switch i8 %7, label %10 [
i8 0, label %22
i8 92, label %8
]
8: ; preds = %4
%9 = call i32 @out_string(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %18
10: ; preds = %4
%11 = add i8 %7, -127
%12 = icmp ult i8 %11, -95
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @out_char(i8 signext %7)
br label %18
15: ; preds = %10
%16 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %7)
%17 = call i32 @out_string(i8* %3)
br label %18
18: ; preds = %8, %15, %13
%19 = phi i32 [ 2, %8 ], [ 4, %15 ], [ 1, %13 ]
%20 = add nuw nsw i32 %6, %19
%21 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
22: ; preds = %4
ret i32 %6
}