#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 */
typedef int /*<<< orphan*/ urle_user_name;
typedef int /*<<< orphan*/ urle_login_token;

/* Variables and functions */
scalar_t__ rc_url_encode(char *, int, char const *);
int snprintf(char *, size_t, char *, char *, char *);
int rc_url_login_with_token(char *buffer, size_t size, const char *user_name,
                            const char *login_token) {
  char urle_user_name[64];
  char urle_login_token[64];
  int written;
  if (rc_url_encode(urle_user_name, sizeof(urle_user_name), user_name) != 0) {
    return -1;
  }
  if (rc_url_encode(urle_login_token, sizeof(urle_login_token), login_token) !=
      0) {
    return -1;
  }
  written =
      snprintf(buffer, size,
               "http://retroachievements.org/dorequest.php?r=login&u=%s&t=%s",
               urle_user_name, urle_login_token);
  return (size_t)written >= size ? -1 : 0;
}


x86 assembly (clang, -O0):
<rc_url_login_with_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     1163 <rc_url_login_with_token+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <rc_url_login_with_token+0xae>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
cmp    $0x0,%rax
je     118e <rc_url_login_with_token+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <rc_url_login_with_token+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x70(%rbp),%rcx
lea    -0xb0(%rbp),%r8
lea    0xe58(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0xb4(%rbp)
movslq -0xb4(%rbp),%rdx
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    %rsi,%rdx
cmovae %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_url_login_with_token>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x40(%rsp),%rdi
mov    $0x40,%esi
call   1030 <rc_url_encode@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1188 <rc_url_login_with_token+0x68>
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1030 <rc_url_encode@plt>
test   %rax,%rax
jne    1188 <rc_url_login_with_token+0x68>
lea    0xe95(%rip),%rdx
lea    0x40(%rsp),%rcx
mov    %rsp,%r8
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
cltq
xor    %ebp,%ebp
cmp    %r14,%rax
adc    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [61 x i8] c"http://retroachievements.org/dorequest.php?r=login&u=%s&t=%s\00"
define i32 @rc_url_login_with_token(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%9 = call i64 @rc_url_encode(i8* %7, i32 64, i8* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %4
%12 = call i64 @rc_url_encode(i8* %8, i32 64, i8* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
%16 = sext i32 %15 to i64
%17 = icmp uge i64 %16, %1
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %11, %4, %14
%20 = phi i32 [ %18, %14 ], [ -1, %4 ], [ -1, %11 ]
ret i32 %20
}