#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 INT_MAX;
int /*<<< orphan*/ putchar(int);
void printchar(char **str, int *len, int c) {
  if (--(*len) > 0) {
    if (*len > INT_MAX / 2) {
      putchar(c);
    } else {
      *(*str)++ = c;
    }
  }
}


x86 assembly (clang, -O0):
<printchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
mov    (%rcx),%eax
add    $0xffffffff,%eax
mov    %eax,(%rcx)
cmp    $0x0,%eax
jle    1188 <printchar+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jle    116b <printchar+0x5b>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    1183 <printchar+0x73>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
jmp    1188 <printchar+0x78>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printchar>:
mov    (%rsi),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,(%rsi)
cmp    $0x2,%ecx
jl     1145 <printchar+0x35>
mov    0x2ec5(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
sar    %esi
cmp    %esi,%eax
jle    1139 <printchar+0x29>
mov    %edx,%edi
jmp    1030 <putchar@plt>
mov    (%rdi),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
mov    %dl,(%rax)
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define void @printchar(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32*, i32** %5
%8 = load i32, i32* %7
%9 = add nsw i32 %8, -1
store i32 %9, i32* %7
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %3
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = load i32, i32* @INT_MAX
%15 = sdiv i32 %14, 2
%16 = icmp sgt i32 %13, %15
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i32, i32* %6
%19 = call i32 @putchar(i32 %18)
br label %26
20: ; preds = %11
%21 = load i32, i32* %6
%22 = trunc i32 %21 to i8
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %23
store i8 %22, i8* %24
br label %26
26: ; preds = %20, %17
br label %27
27: ; preds = %26, %3
ret void
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define void @printchar(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, -1
store i32 %5, i32* %1
%6 = icmp sgt i32 %4, 1
br i1 %6, label %7, label %17
7: ; preds = %3
%8 = load i32, i32* @INT_MAX
%9 = sdiv i32 %8, 2
%10 = icmp sgt i32 %5, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @putchar(i32 %2)
br label %17
13: ; preds = %7
%14 = trunc i32 %2 to i8
%15 = load i8*, i8** %0
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %0
store i8 %14, i8* %15
br label %17
17: ; preds = %11, %13, %3
ret void
}