#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 sscanf(char const *, char *, char *, int *, ...);
int parse_url(const char *url, char *host, int *port) {
  int len;
  if (sscanf(url, "%*[htps]://%1024[^:]:%d%n", host, port, &len) == 2 ||
      sscanf(url, "%1024[^:]:%d%n", host, port, &len) == 2) {
  } else if (sscanf(url, "%*[htps]://%1024[^/]%n", host, &len) == 1) {
    *port = 80;
  } else {
    sscanf(url, "%1024[^/]%n", host, &len);
    *port = 80;
  }
  do {
  } while (0);
  return len;
}


x86 assembly (clang, -O0):
<parse_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xec9(%rip),%rsi
lea    -0x1c(%rbp),%r8
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     1172 <parse_url+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xead(%rip),%rsi
lea    -0x1c(%rbp),%r8
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x2,%eax
jne    1177 <parse_url+0x67>
jmp    11d2 <parse_url+0xc2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe94(%rip),%rsi
lea    -0x1c(%rbp),%rcx
mov    $0x0,%al
call   1030 <sscanf@plt>
cmp    $0x1,%eax
jne    11a9 <parse_url+0x99>
mov    -0x18(%rbp),%rax
movl   $0x50,(%rax)
jmp    11cd <parse_url+0xbd>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6d(%rip),%rsi
lea    -0x1c(%rbp),%rcx
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    -0x18(%rbp),%rax
movl   $0x50,(%rax)
jmp    11d2 <parse_url+0xc2>
jmp    11d7 <parse_url+0xc7>
jmp    11dc <parse_url+0xcc>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_url>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xed7(%rip),%rsi
lea    0xc(%rsp),%r8
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     119f <parse_url+0x8f>
lea    0xec4(%rip),%rsi
lea    0xc(%rsp),%r8
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x2,%eax
je     119f <parse_url+0x8f>
lea    0xeb2(%rip),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1198 <parse_url+0x88>
lea    0xe9f(%rip),%rsi
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <sscanf@plt>
movl   $0x50,(%r14)
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%*[htps]://%1024[^:]:%d%n\00"
@.str.1 = [15 x i8] c"%1024[^:]:%d%n\00"
@.str.2 = [23 x i8] c"%*[htps]://%1024[^/]%n\00"
@.str.3 = [12 x i8] c"%1024[^/]%n\00"
define i32 @parse_url(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = load i32*, i32** %6
%11 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %9, i32* %10, i32* %7)
%12 = icmp eq i32 %11, 2
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i32*, i32** %6
%17 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32* %16, i32* %7)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %13, %3
br label %33
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32* %7)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32*, i32** %6
store i32 80, i32* %26
br label %32
27: ; preds = %20
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32* %7)
%31 = load i32*, i32** %6
store i32 80, i32* %31
br label %32
32: ; preds = %27, %25
br label %33
33: ; preds = %32, %19
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [26 x i8] c"%*[htps]://%1024[^:]:%d%n\00"
@.str.1 = [15 x i8] c"%1024[^:]:%d%n\00"
@.str.2 = [23 x i8] c"%*[htps]://%1024[^/]%n\00"
@.str.3 = [12 x i8] c"%1024[^/]%n\00"
define i32 @parse_url(i8* nocapture %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %1, i32* %2, i32* %4)
%7 = icmp eq i32 %6, 2
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32* %2, i32* %4)
%10 = icmp eq i32 %9, 2
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32* %4)
%13 = icmp eq i32 %12, 1
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 (i8*, i8*, i8*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32* %4)
br label %16
16: ; preds = %11, %14
store i32 80, i32* %2
br label %17
17: ; preds = %16, %8, %3
%18 = load i32, i32* %4
ret i32 %18
}