#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 *, ...);
int /*<<< orphan*/ sscanf(char const *, char *, char *, int *, char *);
int main(void) {
  const char text[] = "http://192.168.0.2:8888/foo/bar";
  char ip[100];
  int port = 80;
  char page[100];
  sscanf(text, "http://%99[^:]:%99d/%99[^\n]", ip, &port, page);
  printf("ip = \"%s\"\n", ip);
  printf("port = \"%d\"\n", port);
  printf("page = \"%s\"\n", page);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x50,-0xa4(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0x110(%rbp),%r8
lea    0xe9f(%rip),%rsi
lea    -0xa4(%rbp),%rcx
call   1040 <sscanf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xa4(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x50,0xc(%rsp)
lea    0xecf(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xa0(%rsp),%rbx
lea    0xc(%rsp),%rcx
lea    0x30(%rsp),%r14
mov    %rbx,%rdx
mov    %r14,%r8
call   1040 <sscanf@plt>
lea    0xec2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.text = [32 x i8] c"http://192.168.0.2:8888/foo/bar\00"
@.str = [28 x i8] c"http://%99[^:]:%99d/%99[^\0A]\00"
@.str.1 = [11 x i8] c"ip = \22%s\22\0A\00"
@.str.2 = [13 x i8] c"port = \22%d\22\0A\00"
@.str.3 = [13 x i8] c"page = \22%s\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca [100 x i8]
store i32 0, i32* %1
%6 = bitcast [32 x i8]* %2 to i8*
store i32 80, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8, i32* %4, i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %15)
ret i32 0
}

LLVM IR (-O2):
@__const.main.text = [32 x i8] c"http://192.168.0.2:8888/foo/bar\00"
@.str = [28 x i8] c"http://%99[^:]:%99d/%99[^\0A]\00"
@.str.1 = [11 x i8] c"ip = \22%s\22\0A\00"
@.str.2 = [13 x i8] c"port = \22%d\22\0A\00"
@.str.3 = [13 x i8] c"page = \22%s\22\0A\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
store i32 80, i32* %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %3, i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %8)
ret i32 0
}