#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*/ __setup_vars(int, char *, char *, char *, char **);
scalar_t__ strlen(char *);
int __calc_left_pad(int flags, char *cur_symb) {
  char cs_precedes, sep_by_space, sign_posn, *signstr;
  int left_chars = 0;
  __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
  if (cs_precedes != 0) {
    left_chars += strlen(cur_symb);
    if (sep_by_space != 0)
      left_chars++;
  }
  switch (sign_posn) {
  case 1:
    left_chars += strlen(signstr);
    break;
  case 3:
  case 4:
    if (cs_precedes != 0)
      left_chars += strlen(signstr);
  }
  return (left_chars);
}


x86 assembly (clang, -O0):
<__calc_left_pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
lea    -0x12(%rbp),%rdx
lea    -0x13(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1040 <__setup_vars@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     118c <__calc_left_pad+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0x0,%eax
je     1187 <__calc_left_pad+0x67>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118c <__calc_left_pad+0x6c>
movsbl -0x13(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x1,%eax
je     11b5 <__calc_left_pad+0x95>
jmp    11a1 <__calc_left_pad+0x81>
mov    -0x28(%rbp),%eax
add    $0xfffffffd,%eax
sub    $0x2,%eax
jb     11d0 <__calc_left_pad+0xb0>
jmp    11f8 <__calc_left_pad+0xd8>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    11f8 <__calc_left_pad+0xd8>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     11f3 <__calc_left_pad+0xd3>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
jmp    11f8 <__calc_left_pad+0xd8>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__calc_left_pad>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0xf(%rsp),%rsi
lea    0xe(%rsp),%rdx
lea    0xd(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1040 <__setup_vars@plt>
mov    0xf(%rsp),%bpl
test   %bpl,%bpl
je     1161 <__calc_left_pad+0x41>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
cmpb   $0x1,0xe(%rsp)
sbb    $0xffffffff,%ebx
jmp    1163 <__calc_left_pad+0x43>
xor    %ebx,%ebx
movsbl 0xd(%rsp),%eax
lea    -0x3(%rax),%ecx
cmp    $0x2,%ecx
jae    118a <__calc_left_pad+0x6a>
test   %bpl,%bpl
je     1181 <__calc_left_pad+0x61>
mov    0x10(%rsp),%rdi
call   1030 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
cmp    $0x1,%eax
je     1175 <__calc_left_pad+0x55>
jmp    1181 <__calc_left_pad+0x61>

LLVM IR (-O0):
define i32 @__calc_left_pad(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %9
%10 = load i32, i32* %3
%11 = call i32 @__setup_vars(i32 %10, i8* %5, i8* %6, i8* %7, i8** %8)
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i64 @strlen(i8* %16)
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %9
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %28
28: ; preds = %25, %15
br label %29
29: ; preds = %28, %2
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
switch i32 %31, label %51 [
i32 1, label %32
i32 3, label %39
i32 4, label %39
]
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = call i64 @strlen(i8* %33)
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = add nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %9
br label %51
39: ; preds = %29, %29
%40 = load i8, i8* %5
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i8*, i8** %8
%45 = call i64 @strlen(i8* %44)
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = add nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %9
br label %50
50: ; preds = %43, %39
br label %51
51: ; preds = %50, %29, %32
%52 = load i32, i32* %9
ret i32 %52
}

LLVM IR (-O2):
define i32 @__calc_left_pad(i32 %0, i8* nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = call i32 @__setup_vars(i32 %0, i8* %3, i8* %4, i8* %5, i8** %6)
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = call i64 @strlen(i8* dereferenceable(1) %1)
%13 = trunc i64 %12 to i32
%14 = load i8, i8* %4
%15 = icmp ne i8 %14, 0
%16 = zext i1 %15 to i32
%17 = add nsw i32 %16, %13
br label %18
18: ; preds = %11, %2
%19 = phi i32 [ 0, %2 ], [ %17, %11 ]
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
switch i32 %21, label %28 [
i32 1, label %23
i32 3, label %22
i32 4, label %22
]
22: ; preds = %18, %18
br i1 %10, label %28, label %23
23: ; preds = %22, %18
%24 = load i8*, i8** %6
%25 = call i64 @strlen(i8* dereferenceable(1) %24)
%26 = trunc i64 %25 to i32
%27 = add i32 %19, %26
br label %28
28: ; preds = %23, %22, %18
%29 = phi i32 [ %19, %18 ], [ %19, %22 ], [ %27, %23 ]
ret i32 %29
}