#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*/ snprintf(char *, size_t, char *, char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int url_modify(char *buf, size_t n, char *url, size_t n2) {
  int len = 0;
  if (!strncasecmp(url, "http://", 7) || !strncasecmp(url, "https://", 8)) {
    len = url[4] == 's' ? 8 : 7;
  }
  if (len == 0) {
    snprintf(buf, n, "http://%s", url);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<url_modify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
je     117b <url_modify+0x5b>
mov    -0x20(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1196 <url_modify+0x76>
mov    -0x20(%rbp),%rax
movsbl 0x4(%rax),%edx
mov    $0x7,%eax
mov    $0x8,%ecx
cmp    $0x73,%edx
cmove  %ecx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11c4 <url_modify+0xa4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe5e(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cb <url_modify+0xab>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_modify>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xec9(%rip),%rsi
mov    %rdx,%rdi
mov    $0x7,%edx
call   1040 <strncasecmp@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     117c <url_modify+0x5c>
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
je     117c <url_modify+0x5c>
lea    0xea5(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1030 <snprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [10 x i8] c"http://%s\00"
define i32 @url_modify(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32 0, i32* %10
%11 = load i8*, i8** %8
%12 = call i32 @strncasecmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i8*, i8** %8
%16 = call i32 @strncasecmp(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%17 = icmp ne i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %14, %4
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 115
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 8, i32 7
store i32 %25, i32* %10
br label %26
26: ; preds = %18, %14
%27 = load i32, i32* %10
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = load i8*, i8** %8
%33 = call i32 @snprintf(i8* %30, i64 %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 0, i32* %5
br label %35
34: ; preds = %26
store i32 -1, i32* %5
br label %35
35: ; preds = %34, %29
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [9 x i8] c"https://\00"
@.str.2 = [10 x i8] c"http://%s\00"
define i32 @url_modify(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = tail call i32 @strncasecmp(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32 @strncasecmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 8)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %4, %7, %10
%13 = phi i32 [ 0, %10 ], [ -1, %7 ], [ -1, %4 ]
ret i32 %13
}