#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*/ printf(char *, char *);
scalar_t__ strlen(char *);
char *flip_da_bits(char *flip) {
  int i = 0;
  printf("flippin' da bits on %s\n", flip);
  for (; i < (int)strlen(flip); i++) {
    if (flip[i] == '1')
      flip[i] = '0';
    else
      flip[i] = '1';
  }
  printf("flipped  da bits on %s\n", flip);
  return flip;
}


x86 assembly (clang, -O0):
<flip_da_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec2(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    11a5 <flip_da_bits+0x85>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1186 <flip_da_bits+0x66>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    1192 <flip_da_bits+0x72>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    1197 <flip_da_bits+0x77>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1143 <flip_da_bits+0x23>
mov    -0x8(%rbp),%rsi
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flip_da_bits>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xed2(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1171 <flip_da_bits+0x51>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x31,(%r14,%rbx,1)
sete   %al
xor    $0x31,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <flip_da_bits+0x30>
lea    0xea0(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"flippin' da bits on %s\0A\00"
@.str.1 = [24 x i8] c"flipped da bits on %s\0A\00"
define i8* @flip_da_bits(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %3
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
%11 = icmp slt i32 %7, %10
br i1 %11, label %12, label %34
12: ; preds = %6
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 49
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 48, i8* %24
br label %30
25: ; preds = %12
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 49, i8* %29
br label %30
30: ; preds = %25, %20
br label %31
31: ; preds = %30
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %6
34: ; preds = %6
%35 = load i8*, i8** %2
%36 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [24 x i8] c"flippin' da bits on %s\0A\00"
@.str.1 = [24 x i8] c"flipped da bits on %s\0A\00"
define i8* @flip_da_bits(i8* returned %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %17
6: ; preds = %1, %6
%7 = phi i64 [ %12, %6 ], [ 0, %1 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 49
%11 = select i1 %10, i8 48, i8 49
store i8 %11, i8* %8
%12 = add nuw nsw i64 %7, 1
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
%16 = icmp slt i64 %12, %15
br i1 %16, label %6, label %17
17: ; preds = %6, %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret i8* %0
}